[codeforces 293]A. Weird Game
[codeforces 293]A. Weird Game
试题描述
Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game.
Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string.
Let's represent Yaroslav's word as s = s1s2... s2n. Similarly, let's represent Andrey's word as t = t1t2... t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper.
The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw.
You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well.
输入
The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word.
It is guaranteed that both words consist of 2·n characters "0" and "1".
输出
输入示例
输出示例
First
数据规模及约定
见“输入”
题解
每个人都可以贪心地取上下都是 1 的位置,取完了再取自己位置是 1 的位置,再完了就取对方是 1 的位置,最后取都是 0 的位置,最后谁 1 多谁赢。(就是遵循“利己损人”的贪心策略)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {
if(Head == Tail) {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
return *Head++;
}
int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 2000010
int n;
char s1[maxn], s2[maxn]; int main() {
n = (read() << 1);
scanf("%s%s", s1 + 1, s2 + 1); int cnt10 = 0, cnt01 = 0, cnt11 = 0, fir = 0, sec = 0;
for(int i = 1; i <= n; i++)
cnt10 += (s1[i] == '1' && s2[i] == '0'),
cnt01 += (s1[i] == '0' && s2[i] == '1'),
cnt11 += (s1[i] == '1' && s2[i] == '1');
sec = (cnt11 >> 1);
fir = cnt11 - sec;
if(cnt11 & 1) {
if(cnt01 < cnt10) {
fir += cnt01 + (cnt10 - cnt01 >> 1);
sec += cnt01;
}
if(cnt01 > cnt10) {
fir += cnt10;
sec += cnt10 + (cnt01 - cnt10 - (cnt01 - cnt10 >> 1));
}
if(cnt01 == cnt10) {
fir += cnt10;
sec += cnt01;
}
}
else {
if(cnt01 < cnt10) {
fir += cnt01 + (cnt10 - cnt01 - (cnt10 - cnt01 >> 1));
sec += cnt01;
}
if(cnt01 > cnt10) {
fir += cnt10;
sec += cnt10 + (cnt01 - cnt10 >> 1);
}
if(cnt01 == cnt10) {
fir += cnt10;
sec += cnt01;
}
} if(fir > sec) puts("First");
if(fir < sec) puts("Second");
if(fir == sec) puts("Draw"); return 0;
}
[codeforces 293]A. Weird Game的更多相关文章
- [codeforces 293]B. Distinct Paths
[codeforces 293]B. Distinct Paths 试题描述 You have a rectangular n × m-cell board. Some cells are alrea ...
- Codeforces 946 B.Weird Subtraction Process
B. Weird Subtraction Process time limit per test 1 second memory limit per test 256 megabytes inpu ...
- 【codeforces 789D】Weird journey
[题目链接]:http://codeforces.com/problemset/problem/789/D [题意] 给你n个点,m条边; 可能会有自环 问你有没有经过某两条边各一次,然后剩余m-2条 ...
- 【codeforces 779B】Weird Rounding
[题目链接]:http://codeforces.com/contest/779/problem/B [题意] 问你要删掉几个数字才能让原来的数字能够被10^k整除; [题解] /* 数字的长度不大; ...
- 3.26-3.31【cf补题+其他】
计蒜客)翻硬币 //暴力匹配 #include<cstdio> #include<cstring> #define CLR(a, b) memset((a), (b), s ...
- Codeforces Round #300 D. Weird Chess 水题
D. Weird Chess Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/proble ...
- Codeforces Round #525 (Div. 2) F. Ehab and a weird weight formula
F. Ehab and a weird weight formula 题目链接:https://codeforces.com/contest/1088/problem/F 题意: 给出一颗点有权值的树 ...
- Codeforces Round #407 (Div. 1) B. Weird journey —— dfs + 图
题目链接:http://codeforces.com/problemset/problem/788/B B. Weird journey time limit per test 2 seconds m ...
- codeforces 407 div1 B题(Weird journey)
codeforces 407 div1 B题(Weird journey) 传送门 题意: 给出一张图,n个点m条路径,一条好的路径定义为只有2条路径经过1次,m-2条路径经过2次,图中存在自环.问满 ...
随机推荐
- asp.net下载文件几种方式
测试时我以字符流的形式下载文件,可行,前几个仅作参考 protected void Button1_Click(object sender, EventArgs e) { /* 微软为Respo ...
- iOS - 视频循环播放
录制完视频后,我们想在录制视频的预览层上无限循环播放我们的小视频,是不是很炫酷,这时候我们就有三中选择了:1.MPMoviePlayerController2.AVPlayer3.AVAssetRea ...
- java和linux的编码
最近要使用中科院计算所的关键词工具NLPIR,用java调用,在windows下测试后放到linux下跑,就发现会有乱码. windows下默认是GBK,linux下是utf-8,因此在意料之中(尽管 ...
- at org.apache.catalina.loader.WebappClassLoader.loadClass问题处理
在连接oracle数据库时,正常的java application可以连接,但是到javabean web中就出错,说是Class.forName(dirver)找不到驱 动,问题是,我将oracle ...
- Java设计模式-观察者模式(Observer)
包括这个模式在内的接下来的四个模式,都是类和类之间的关系,不涉及到继承,学的时候应该 记得归纳,记得本文最开始的那个图.观察者模式很好理解,类似于邮件订阅和RSS订阅,当我们浏览一些博客或wiki时, ...
- Oracle分页查询语句
SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM (此处添加你要分页的表)) A WHERE ROWNUM <= 14000)WH ...
- codevs3031 最富有的人
题目描述 Description 在你的面前有n堆金子,你只能取走其中的两堆,且总价值为这两堆金子的xor值,你想成为最富有的人,你就要有所选择. 输入描述 Input Description 第一行 ...
- FOJProblem 2214 Knapsack problem(01背包+变性思维)
http://acm.fzu.edu.cn/problem.php?pid=2214 Accept: 4 Submit: 6Time Limit: 3000 mSec Memory Lim ...
- c#中的23种设计模式
C# 23种设计模式汇总 创建型模式 工厂方法(Factory Method) 在工厂方法模式中,工厂方法用来创建客户所需要的产品,同时还向客户隐藏了哪种具体产品类将被实例化这一细节.工厂方法模式的核 ...
- Nginx 配置文件详解
user nginx ; #用户 worker_processes 8; #工作进程,根据硬件调整,大于等于cpu核数 error_log logs/nginx_error.log crit; #错误 ...