zoukankan      html  css  js  c++  java
  • CodeForces 203C Photographer

    简单贪心。注意内存够大,能满足所有顾客的特殊情况。

     1 #include <iostream>
     2 #include <cstring>
     3 #include <algorithm>
     4 
     5 #define maxn 100010
     6 
     7 using namespace std;
     8 
     9 typedef long long ll;
    10 
    11 struct node {
    12 ll c,id;
    13 }c[maxn];
    14 
    15 bool cmp (node x,node y){
    16 if (x.c<y.c)
    17 return true ;
    18 return false ;
    19 }
    20 
    21 int main (){
    22 ll n,d,x,y,a,b;
    23 ll ans,sum;
    24 while (cin>>n>>d){
    25 cin>>a>>b;
    26 for (int i=0;i<n;i++){
    27 cin>>x>>y;
    28 c[i].c=a*x+b*y;
    29 c[i].id=i+1;
    30 }
    31 sort (c,c+n,cmp);
    32 sum=ans=0;
    33 for (int i=0;i<n;i++){
    34 sum+=c[i].c;
    35 if (sum>d){
    36 ans=i;
    37 break ;
    38 }
    39 if (i==n-1) //所有顾客都能满足
    40 ans=n;
    41 }
    42 cout<<ans<<endl;
    43 for (int i=0;i<ans;i++){
    44 cout<<c[i].id<<" ";
    45 }
    46 cout<<endl;
    47 }
    48 return 0;
    49 }
  • 相关阅读:
    安卓中期小作业
    安卓大作业UI预定搞
    实验3
    实验一总结
    实验8 SQLite数据库操作
    实验6 在应用程序中播放音频和视频
    实验4 颜色、字符串资源的使用
    实验四
    实验三
    实验二
  • 原文地址:https://www.cnblogs.com/gfc-g/p/3844279.html
Copyright © 2011-2022 走看看