P1478 陶陶摘苹果(升级版)
#include<iostream>
#include<algorithm>
using namespace std;
int n,s,a,b,x_,y_,can,rest,ans;
struct apple{
int xi,yi;
}ap[50005];
int cmp(apple x,apple y){
return x.yi<y.yi;
}
int main(){
cin>>n>>s>>a>>b;
for(int i=1;i<=n;i++){
cin>>x_>>y_;
if(x_<=a+b){
can++;
ap[can].xi=x_;
ap[can].yi=y_;
}
}
sort(ap+1,ap+can+1,cmp);
rest=s;
ans=0;
for(int i=1;rest>=ap[i].yi&&i<=can;i++){
ans++;
rest-=ap[i].yi;
}
cout<<ans;
return 0;
}
P1203 [USACO1.1]坏掉的项链Broken Necklace
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
char s[700],c;
int a, b, w, ans;
int main(){
int n;
scanf("%d%s",&n,s);
memcpy(s+n,s,n);
for(int i = 0; i < n<<1; i++) {
if(s[i] == 'w') b++,w++;else
if(s[i] == c ) b++,w=0;else
ans=max(ans,a+b),a=b-w,b=w+1,w=0,c=s[i];
}
ans=max(ans,a+b);
printf("%d\n",min(ans,n));
return 0;
}
P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers
#include<map>
#include<string>
#include<vector>
#include<iostream>
using namespace std;
int NP,money,num;
map<string,int> m;//存钱数
vector<string> id;//存人名
int main(){
cin>>NP;
string tmp;
for(int i=1;i<=NP;i++){
cin>>tmp;
id.push_back(tmp);
}
for(int i=1;i<=NP;i++){
cin>>tmp>>money>>num;
if(money==0||num==0)continue;
m[tmp]-=money;
m[tmp]+=money%num;
for(int j=1;j<=num;j++){
cin>>tmp;
m[tmp]+=money/num;
}
}
for(vector<string>::iterator i=id.begin();i!=id.end();i++)
cout<<*i<<" "<<m[*i]<<endl;//遍历输出
return 0;
}
P1095 守望者的逃离
#include<bits/stdc++.h>
#define MAX_INT ((unsigned)(-1)>>1)
#define MIN_INT (~MAX_INT)
#define pi 3.1415926535898
using namespace std;
int f[300005];
int main(void)
{
int m,s,t;cin>>m>>s>>t;
for(int i=1;i<=t;i++){
if(m>=10) f[i]=f[i-1]+60,m-=10;
else f[i]=f[i-1],m+=4;
}
for(int i=1;i<=t;i++){
f[i]=max(f[i],f[i-1]+17);
if(f[i]>=s){
cout<<"Yes"<<endl<<i;
return 0;
}
}
cout<<"No"<<endl<<f[t];
return 0;
}