Codeforces Round #173 (Div. 2) Problem B
B.Painting Eggs
题目大意是:J画了n个鸡蛋,分别可以买给A 和G,对于每个鸡蛋A 和G的出价都不同,但是要求,最后卖给A 和G 两人鸡蛋的差价不超过500;
/*
题目很水,当时没看懂,所以没做出来,导致又扣了57分;o(︶︿︶)o 唉
要是每次的题目都是中文题就好了,这也应该是很多做codeforces 的中国学生的期待吧;
英语这块软肋怎么办呢。。。
*/
贪心:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <string> #include <iomanip> #define maxn 1000010 char str[maxn]; using namespace std; int main(int argc, char *argv[]) { int n,sa,sb,a,b,i=0; sa = sb = 0; cin>>n; while(n--) { cin>>a>>b; if(sa+a-sb<=500) { sa += a; str[i++] = 'A'; } else { if(sb+b-sa<=500) { sb += b; str[i++] = 'G'; } else { puts("-1"); } } } puts(str); return 0; }