标签:gre strong out table sea any printf date int
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 9578 | Accepted: 2785 |
Description
Input
Output
Sample Input
3 5 70 30 25 50 21 20 20 5 18 35 30
Sample Output
35
Hint
Source
/* * @Author: Lyucheng * @Date: 2017-07-20 09:47:21 * @Last Modified by: Lyucheng * @Last Modified time: 2017-07-20 17:56:01 */ /* 题意:给你C个奶牛参加考试的分数,和需要奖学金的数目,让你从中选N头奶牛,需要总奖学金的数目不超过F,并且分数的 中位数最大 思路:按照分数排序,二分中位数,有个问题就是判断问题可能会超时 细节:判断的时候还有给他排一下序,这样才能去到最小的,还要特判n==1的时候 */ #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> #define MAXN 100005 using namespace std; struct Node{ int score,cost; bool operator < (const Node & other) const{ if(score==other.score) return cost<other.cost; return score < other.score; } }node[MAXN]; int n,c,f; Node pos[MAXN]; bool cmp(Node a,Node b){ return a.cost<b.cost; } bool ok(int x){ int sum=f-node[x].cost;//总的钱数 int cur=0; for(int i=1;i<=c;i++){ if(i==x) continue; pos[++cur]=node[i]; } sort(pos+1,pos+cur+1,cmp); int cnt0=0,cnt1=0;//统计大于小于 int cnt2=0;//统计等于 for(int i=1;i<=cur;i++){ if(sum>=pos[i].cost){ if(pos[i].score==node[x].score){ sum-=pos[i].cost; cnt2++; }else if(pos[i].score<node[x].score){ if(cnt0<n/2){ sum-=pos[i].cost; cnt0++; } }else if(pos[i].score>node[x].score){ if(cnt1<n/2){ sum-=pos[i].cost; cnt1++; } } } } // cout<<node[x].score<<" "<<cnt0<<" "<<cnt1<<" "<<cnt2<<endl; if(cnt0+cnt1+cnt2>=n-1) return true; return false; } int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(scanf("%d%d%d",&n,&c,&f)!=EOF){ for(int i=1;i<=c;i++){ scanf("%d%d",&node[i].score,&node[i].cost); } if(n==1){ sort(node+1,node+c+1,cmp); bool f=false; for(int i=c;i>=1;i--){ if(node[i].cost<=f){ printf("%d",node[i].score); f=true; break; } } if(f==false){ puts("-1"); } continue; } sort(node+1,node+c+1); int l=1,r=c,mid; int res=-1; while(l<=r){ mid=(l+r)/2; if(ok(mid)==true){ l=mid+1; res=node[mid].score; }else{ r=mid-1; } } printf("%d\n",res); } return 0; }
poj 2010 Moo University - Financial Aid
标签:gre strong out table sea any printf date int
原文地址:http://www.cnblogs.com/wuwangchuxin0924/p/7212601.html