记录编号 123798 评测结果 AAAAAAAAAA
题目名称 [USACO Mar]提高速度 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.013 s
提交时间 2014-09-28 21:43:50 内存使用 0.43 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint; 
const int INF=0x7ffffff;
const double eps=1e-6;
//==============struct declaration==============
struct Items{
  int f,m;
  friend inline istream &operator >>(istream &is,Items &it){
    is>>it.f>>it.m;
    return is;
  }
};
//==============var declaration=================
const int MAXN=10010;
Items item[MAXN];
int n,m,f,rank[MAXN];
//==============function declaration============
bool cmp(int a,int b){return (double(item[a].f)/item[a].m-double(item[b].f)/item[b].m>eps)||(fabs(double(item[a].f)/item[a].m-double(item[b].f)/item[b].m)<eps&&item[a].m<item[b].m);}
//==============main code=======================
int main()
{  
  string FileName="sboost";//程序名 
  string FloderName="COGS";//文件夹名 
  freopen((FileName+".in").c_str(),"r",stdin);
  freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG  
  system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
  clock_t Start_Time=clock();
#endif    
  ios::sync_with_stdio(false);
  cin>>f>>m>>n;
  For(i,1,n){
    rank[i]=i;
    cin>>item[i];
  }
  bool suc=false;
  sort(rank+1,rank+1+n,cmp);
  vector <int> od;
  For(i,1,n){
    int x=rank[i];
    if (double(f+item[x].f)/(m+item[x].m)>double(f)/m){
      f+=item[x].f;
      m+=item[x].m;
      od.push_back(x);
      suc=true;
    }
  }
  
  if (!suc)
    cout<<"NONE"<<endl;
  else{
    sort(od.begin(),od.end());
    For(i,0,od.size()-1)
      cout<<od[i]<<endl;
  }
#ifdef DEBUG  
  clock_t End_Time=clock();
  cout<<endl<<endl<<"Time Used: "<<double(End_Time-Start_Time)*1000/(CLOCKS_PER_SEC)<<" Ms"<<endl;
#endif    
  return 0;
}
//================fuction code====================