其他分享
首页 > 其他分享> > poj 3664(水题,结构体排序)

poj 3664(水题,结构体排序)

作者:互联网

#include<iostream>
#include<algorithm>
using namespace std;
struct Node{
    int id,a1,a2;
}vote[50005];
bool cmp(struct Node v1,struct Node v2){
    return v1.a1>v2.a1;
}
int main(){
    int n,k,ans,ansi;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d%d",&vote[i].a1,&vote[i].a2);
        vote[i].id = i+1;
    }
    sort(vote,vote+n,cmp);
//    for(int i=0;i<k;i++){
//        cout<<vote[i].a1<<" "<<vote[i].a2<<endl;
//    }
    ans = vote[0].a2;
    ansi = vote[0].id;
    for(int i=1;i<k;i++)
        if(vote[i].a2>ans){
            ans = vote[i].a2;
            ansi = vote[i].id;
        }
    printf("%d\n",ansi);
    return 0;
}

 

标签:Node,3664,struct,水题,int,a1,ansi,poj,vote
来源: https://www.cnblogs.com/stevenzrx/p/15087896.html