[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次,图中存在自环.问满 ...
随机推荐
- sql server 使用函数辅助查询
函数是所有语言系统下都具备的内部数据处理过程,SQL SERVER也同样内置了许多函数.在SQL SERVER中,函数是由一个或多个T-SQL语句组成的子程序.利用函数可以简化数据的处理操作. 函数分 ...
- C#基础知识系列六(静态类和静态类成员)
静态类 静态类与非静态类基本相同,但存在一个区别:静态类不能实例化. 也就是说,不能使用 new 关键字创建静态类类型的变量. 因为没有实例变量,所以要使用类名本身访问静态类的成员. 例如,如果名为 ...
- EntityFramework_MVC4中EF5 新手入门教程之七 ---7.通过 Entity Framework 处理并发
在以前的两个教程你对关联数据进行了操作.本教程展示如何处理并发性.您将创建工作与各Department实体的 web 页和页,编辑和删除Department实体将处理并发错误.下面的插图显示索引和删除 ...
- HTML5——播放器
有了H5的Video,妈妈再也不用担心我没安Flash插件了 根据Video提供的方法和属性,简单练习了一下,不说废话,直接上图片和代码 <html><head><tit ...
- java.lang.NoClassDefFoundError: com/sun/mail/util/BEncoderStream
:java.lang.NoClassDefFoundError: com/sun/mail/util/BEncoderStream 这个问题是Mail.jar包没有引入到java路径中,或者是版本的问 ...
- history命令显示出详细时间
文章摘自: http://blog.csdn.net/lixiaohuiok111/article/details/34428161 http://blog.csdn.net/lixiaohuiok1 ...
- JQuery思维导图
- 在Eclipse 中下载 开源中国码云上的项目
功能:使用开源中国代码托管(码云)来托管代码,本地的使用Eclipse,该如何配置? 步骤: 1/ 在码云 上建一个工程,(为了访问托管工程的权限) 2/ 在eclipse中打开名字叫做“Git ...
- POJ 2559 Largest Rectangle in a Histogram
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18942 Accepted: 6083 Description A hi ...
- POJ 3258 River Hopscotch
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11031 Accepted: 4737 ...