贪心 Codeforces Round #173 (Div. 2) B. Painting Eggs
/*
题意:给出一种方案使得abs (A - G) <= 500,否则输出-1
贪心:每次选取使他们相差最小的,然而并没有-1:)
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std; const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f; int main(void) //Codeforces Round #173 (Div. 2) B. Painting Eggs
{
// freopen ("B.in", "r", stdin); int n;
while (scanf ("%d", &n) == )
{
string ans = ""; int sum_a = , sum_g = ;
for (int i=; i<=n; ++i)
{
int x, y;
scanf ("%d%d", &x, &y);
if (abs (sum_a + x - sum_g) <= abs (sum_g + y - sum_a)) {ans += "A"; sum_a += x;}
else {ans += 'G'; sum_g += y;}
} cout << ans << endl;
} return ;
}
贪心 Codeforces Round #173 (Div. 2) B. Painting Eggs的更多相关文章
- 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...
- 贪心 Codeforces Round #301 (Div. 2) B. School Marks
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...
- 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...
- 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges
题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...
- 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
- 字符串处理/贪心 Codeforces Round #307 (Div. 2) B. ZgukistringZ
题目传送门 /* 题意:任意排列第一个字符串,使得有最多的不覆盖a/b字符串出现 字符串处理/贪心:暴力找到最大能不覆盖的a字符串,然后在b字符串中动态得出最优解 恶心死我了,我最初想输出最多的a,再 ...
- 贪心 Codeforces Round #273 (Div. 2) C. Table Decorations
题目传送门 /* 贪心:排序后,当a[3] > 2 * (a[1] + a[2]), 可以最多的2个,其他的都是1个,ggr,ggb, ggr... ans = a[1] + a[2]; 或先2 ...
- 贪心 Codeforces Round #109 (Div. 2) B. Combination
题目传送门 /* 贪心:按照能选的个数和点数降序排序,当条件不符合就break,水题啊! */ #include <cstdio> #include <algorithm> # ...
随机推荐
- [React] PureComponent in React
In this lesson, you will learn how to use PureComponent in React to reduce the number of times your ...
- js性能优化之函数节流(分流函数)
函数节流的原理 比如我们在window.onresize事件中要打印当前浏览器窗口的大小,在我们通过拖拽来改变窗口大小时候,打印窗口大小这个工作1s就运行了10次.而实际上我们只需要2次或者3次. 比 ...
- Android +NDK+eclipse+opengl ES2.0 开启深度測试
參考:https://www.opengl.org/discussion_boards/showthread.php/172736-OpenGL-ES-Depth-Buffer-Problem 环境: ...
- 设计模式 之代理(Proxy)模式
为什么这里要定义代理呢?所谓代理代理,当然就是你不想做的事.找别人去做,这就是代理.所以,当你写代码的时候.你想保持类的简单性.重用性.你就能够把事件尽量都交给其他类去做.自己仅仅管做好自己的事.也就 ...
- MongoDB 自己定义函数
定义 db.system.js.insert({ _id : "TestConcat", value : function TestConcat(s1, s2){ return s ...
- eclipse maven 插件的安装和配置
maven3 安装: 安装 Maven 之前要求先确定你的 JDK 已经安装配置完毕.Maven是 Apache 下的一个项目.眼下最新版本号是 3.0.4.我用的也是这个. 首先去官网下载 Mave ...
- 我的gulp.js清单
var gulp = require('gulp'), cssmin = require('gulp-clean-css'), //压缩css文件 concat = require('gulp-con ...
- iOS与HTML交互问题
一. 加载后台传过来的HTML标签,文字都能正常显示但是图片显示不了.找问题找了很久没有发现那个地方写错,也问了别人都不知道,后来问了Android才知道,后台传过来的HTML标签,有些是转义过的.移 ...
- Android 4.4.2 动态加入JNI库方法记录 (二 app应用层)
欢迎转载,务必注明出处:http://blog.csdn.net/wang_shuai_ww/article/details/44458553 源代码下载地址:http://download.csdn ...
- 发布Java桌面程序
我拿了一份桌面工具的开源代码,修修改改,在elipse上运行,感觉良好,但到了发布应用程序,就傻眼了.我居然不知道咋发布! 呵呵,不愧是Java小白! 如果是微软阵营,直接就编译成exe了.但java ...