AtCoder - 2153 An Ordinary Game list模拟 || 博弈
http://abc048.contest.atcoder.jp/tasks/arc064_b?lang=en
在vj里面用list模拟水过去了,然后感觉vj不靠谱,上atcoder交,果然tle
我的思路是这样的,first那个是没有必胜策略的,赢就是赢,随便拿哪一个都是赢。
所以只需要找到有多少个能拿的就行了。用list模拟下,TLE.
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
#include <list>
list<char>theList;
const int maxn = 1e5 + ;
char str[maxn];
void work() {
scanf("%s", str + );
int lenstr = strlen(str + );
for (int i = ; i <= lenstr; ++i) {
theList.push_back(str[i]);
}
// for (list<char> :: iterator it = theList.begin(); it != theList.end(); ++it) {
// cout << *it;
// }
int ans = ;
while (theList.size() > ) {
if (theList.size() == && theList.front() == theList.back()) break;
list<char> :: iterator itBegin = theList.begin();
itBegin++;
list<char> :: iterator itEnd = theList.end();
itEnd--;
list<char> :: iterator itBeginPre = theList.begin();
list<char> :: iterator itBeginNext = itBegin; itBeginNext++;
bool flag = false;
while (itBegin != itEnd) {
if (*itBeginPre == *itBeginNext) {
itBeginPre++;
itBegin++;
itBeginNext++;
} else {
theList.erase(itBegin);
flag = true;
break;
}
}
if (!flag) break;
ans++;
}
// cout << ans << endl;
if (ans & ) {
cout << "First" << endl;
} else cout << "Second" << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}
那么就需要快速找到有多少东西能拿,一般情况下,能拿的东西是lenstr - 2个,减去头和尾
博弈:
分为两种情况:
1、头和尾相等,这个时候能拿的东西次数 - 1,
2、头和尾不等,拿的东西次数不变
然后判断奇偶性就好。
那么死锁怎么办?就是像ababa
这里能拿的个数是0,但是按照上面的,是2.
看看基本的死锁是:aba,这样,那么再添加2个,可以形成新的死锁ababa
注意到添加元素的个数必定要是偶数,这个不影响奇偶性。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
#include <list>
list<char>theList;
const int maxn = 1e5 + ;
char str[maxn];
void work() {
scanf("%s", str + );
int lenstr = strlen(str + );
lenstr -= ;
if (str[] == str[strlen(str + )]) lenstr--;
if (lenstr & ) {
cout << "First" << endl;
} else cout << "Second" << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}
AtCoder - 2153 An Ordinary Game list模拟 || 博弈的更多相关文章
- atcoder C - Snuke and Spells(模拟+思维)
题目链接:http://agc017.contest.atcoder.jp/tasks/agc017_c 题解:就是简单的模拟一下就行.看一下代码就能理解 #include <iostream& ...
- 【AtCoder】ARC095 E - Symmetric Grid 模拟
[题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...
- ACM-ICPC 2018 徐州赛区网络预赛 B BE, GE or NE 【模拟+博弈】
题目:戳这里 题意:A和B博弈,三种操作分别是x:加a,y:减b,z:取相反数.当x或y或z为0,说明该操作不可取,数据保证至少有一个操作可取,给定一个区间(l,k)和原始数字m,如果A和B在n次操作 ...
- Atcoder Beginner Contest 115 D Christmas 模拟,递归 B
D - Christmas Time limit : 2sec / Memory limit : 1024MB Score : 400 points Problem Statement In some ...
- AtCoder 杂题训练
前言: 因为要普及了,今年没一等就可以退役去学文化课了,所以暑假把历年noip普及组都刷了一遍,离noip还有50+天,想弄点强化训练什么的. 想了想,就这些天学文化课之余有空就把AtCoder之前那 ...
- hdu_2147_kiki's game(博弈)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2147 题意:给你一个矩阵,从右上走到左下,每次只能向左或向下或向斜下走一格,先走到最后一格的会输,问k ...
- hdu-4023-博弈(模拟)
Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submis ...
- NOI前训练日记
向别人学习一波,记点流水帐.17.5.29开坑. 5.29 早晨看了道据说是树状数组优化DP的题(hdu5542),然后脑补了一个复杂度500^3的meet in the middle.然后死T... ...
- NOIP 2020 游记
第一次写比赛游记,请多多指教! I. 考前 由于最近参加了太多太多比赛了,所以没有敲模板题: 考前一周:主要是在做 AtCoder 的题和 xjoi 的模拟赛,相当于恶补了一些套路吧! 考前一天:上午 ...
随机推荐
- Android应用之——最新版本号SDK V2.4实现QQ第三方登录
为什么要写这篇博客呢?由于.我在做这个第三方登录的时候,找了非常多资料,发现要么就是过时了.要么就是说的非常不清楚.非常罗嗦.并且非常多都是一些小demo,不是什么实例.甚至连腾讯官方的文档都有这个问 ...
- strong and weak 强引用和弱引用的差别
(weak和strong)不同的是 当一个对象不再有strong类型的指针指向它的时候 它会被释放 ,即使还有weak型指针指向它. 一旦最后一个strong型指针离去 .这个对象将被释放,全部剩余 ...
- web中使用svg失量图形及ie8以下浏览器的处理方式
直接上代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <me ...
- POJ3436 ACM Computer Factory —— 最大流
题目链接:https://vjudge.net/problem/POJ-3436 ACM Computer Factory Time Limit: 1000MS Memory Limit: 655 ...
- Java虚拟机一览表
免费和开源的 Java 虚拟机AegisVM (inactive since 2004).Apache Harmony — supports several architectures and sys ...
- ExtJS常用代码集合
ExtJS常用代码集合,包括弹出提示框,登陆框,树状结构等等.1. [代码]弹出提示框 <html> <head> <title>Ge ...
- html5--6-59 其他常用CSS属性
html5--6-59 其他常用CSS属性 实例 学习要点 了解opacity属性:透明度设定 了解cursor属性:自定义鼠标样式 了解CSS新单位rem和em的区别 了解轮廓outline的设置 ...
- Code-NFine:NFine介绍
ylbtech-Code-NFine:NFine介绍 1. NFine平台介绍返回顶部 1. 使用时请务必保留来源,请勿用于违反我国法律的web平台.如诈骗等非法平台网站.版权最终解释权归<NF ...
- 039--CSS
一.CSS定义 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. ''' selector { property: value; property: value; ... propert ...
- Mysql基础调优
mysql基础的优化方式 1.利用索引加快查询速度 2.利用查询缓存或者旁挂式缓存,提高访问速度 缓存:k/v key:查询语句的hash值 value:查询语句的执行结果 哪些查询可能不会被缓存? ...