Codeforces 1368F - Lamps on a Circle (交互博弈)
这题也太新颖了吧.. 交互博弈 以前一直以为交互只能出二分
题意:长度为n的环形灯 玩家有两种操作 结束游戏 或者选择k个灯点亮 每次这个k是玩家自己选的
玩家操作后让电脑操作 电脑选择一个最优的点x 然后关掉从x开始的连续k个灯
玩家想要点亮更多的灯 电脑则相反
让你来操作 如果达到了理论上最多灯的状态就算ac了
题解:模拟一下操作就找到规律了..
如果玩家上一次操作点亮了k个灯 如果当前连续亮灯的最长序列为x <= k
那么电脑操作了之后 至少会多点亮一个灯 就这样一直贪心下去..
所以我们一开始枚举 最长的连续亮灯长度
举个例子枚举的最长是2 就类似110110110.. 的把每个灯标记 1就标记为最后要点亮的灯
再比如n=11的时候 枚举的最长=2 11011011010 注意n和1相邻一定为0
然后模拟一下就发现这种情况 能最多点亮5个 = (n/3)*(2) + (n%3-1) - 2
k = 7 11011011010 -> 00000001010
k = 5 11011011010 -> 00000011010
k = 4 11011011010 -> 00001011010
k = 3 11011011010 -> 00011011010
之后无论如何也不能点亮更多灯了
然后枚举每一个长度 选一个最优的

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <string.h>
#include <string>
using namespace std; int vis[1005];
int now[1005];
vector<int> g;
int main() {
int n;
cin>>n; int ans = 0;
int fz = 2;
for(int i = 2; i <= n / 2; i++) {
int res = (n / i) * (i - 1);
if(n % i != 0) res += n % i - 1;
res -= (i - 1);
if(res > ans) ans = res, fz = i;
}
//cout << ans << endl;
for(int i = 1; i <= n; i++) if(i % fz) vis[i] = 1;
vis[n] = 0; int lask = 0;
int x = 0;
while(1) {
if(x == -1) break;
int rr = 0;
int pos = x;
while(lask--) {
now[pos] = 0;
pos++;
if(pos > n) pos = 1;
}
for(int i = 1; i <= n; i++) if(now[i]) rr++; if(rr >= ans) {
puts("0");
cout.flush();
break;
} g.clear();
for(int i = 1; i <= n; i++) {
if(!now[i] && vis[i]) {
now[i] = 1;
g.push_back(i);
}
}
lask = g.size();
printf("%d", lask);
for(int i = 0; i < lask; i++) printf(" %d", g[i]); puts("");
cout.flush();
cin>>x;
}
return 0;
}
Codeforces 1368F - Lamps on a Circle (交互博弈)的更多相关文章
- Codeforces 549C The Game Of Parity【博弈】
C语言纠错大赛的一道题,正好拿来补博弈~~ 给的代码写的略奇葩..不过还是直接在上面改了.. 题目链接: http://codeforces.com/problemset/problem/549/C ...
- Codeforces 388C Fox and Card Game (贪心博弈)
Codeforces Round #228 (Div. 1) 题目链接:C. Fox and Card Game Fox Ciel is playing a card game with her fr ...
- codeforces 455B A Lot of Games(博弈,字典树)
题目 参考自博客:http://blog.csdn.net/keshuai19940722/article/details/38455269 //字典树,博弈 根据当前节点的后续来确定当前节点的状态, ...
- codeforces 679A Bear and Prime 100 交互
第一次交互题,记录一下吧 #include <cstdio> #include <iostream> #include <ctime> #include <v ...
- Codeforces 897D. Ithea Plays With Chtholly (交互)
题目链接:D. Ithea Plays With Chtholly 题意: 给你n张纸,在纸上写字(在 1 - c之间)可以写m次数 (,).(主要是交互,让你判断) 题解: 首先,看到m>=n ...
- [Educational Round 10][Codeforces 652F. Ants on a Circle]
题目连接:652F - Ants on a Circle 题目大意:\(n\)个蚂蚁在一个大小为\(m\)的圆上,每个蚂蚁有他的初始位置及初始面向,每个单位时间蚂蚁会朝着当前面向移动一个单位长度,在遇 ...
- Vladik and Favorite Game CodeForces - 811D (思维+BFS+模拟+交互题)
D. Vladik and Favorite Game time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #281 (Div. 2) D(简单博弈)
题目:http://codeforces.com/problemset/problem/493/D 题意:一个n*n的地图,有两个人在比赛,第一个人是白皇后开始在(1,1)位置,第二个人是黑皇后开始在 ...
- Codeforces 652F Ants on a Circle
Ants on a Circle 感觉这个思路好巧妙啊. 我们能发现不管怎么碰撞,初始态和最终态蚂蚁间的相对顺序都是一样的, 并且所占的格子也是一样的, 那么我们就只需要 找到其中一个蚂蚁的最终位置就 ...
随机推荐
- [从源码学设计]蚂蚁金服SOFARegistry 之 ChangeNotifier
[从源码学设计]蚂蚁金服SOFARegistry 之 ChangeNotifier 目录 [从源码学设计]蚂蚁金服SOFARegistry 之 ChangeNotifier 0x00 摘要 0x01 ...
- laravel5.4 接入qq第三方登录
第一步:先composer安装需要用到的依赖,命令行如下 composer require socialiteproviders/qq 第二步:在config/app.php 中的 providers ...
- 在阿里云托管的k8s上使用nas做动态存储
前言 关于aliyun托管k8s的存储插件主要有两种: CSI # kubectl get pod -n kube-system | grep csi-plugin csi-plugin-8bbnw ...
- APPIUM-Android自动化元素定位方式
一.常用元素定位方法 appium从selenium中继承了所有的元素定位方法, 并且增加了一些自己的元素定位方式,下方截图分别为selenium和MobileBy包源码: 但是从继承selenium ...
- Azure Key Valut 简介
Azure Key Vault(密钥库)是用于安全地存储和访问Secret的云服务,Secret是需要严格控制访问权限的内容,例如API密钥,密码,证书或加密密钥.Key Vault Service支 ...
- 怎么启用apache的mod_log_sql模块将所有的访问信息直接记录在mysql中
怎么启用apache的mod_log_sql模块将所有的访问信息直接记录在mysql中
- golang语言初体验
Go(又称 Golang)是 Google 的 Robert Griesemer,Rob Pike 及 Ken Thompson 开发的一种静态强类型.编译型语言.Go 语言语法与 C 相近,但功能上 ...
- iptables原理及防火墙规则语法基础
Iptables 防火墙 学习总结: 三张表介绍: filter负责过滤数据包,包括的规则链有,input(进),output(出)和forward(转发); nat则涉及到网络地址转换,包括的规则 ...
- the7主题 一个强大的wordpress 主题 html5拖拽式建站系统
演示地址 http://the7.net The7汉化主题.可视化编辑器和终极交互式模块插件完全无缝集成,可以让你完全自由的布局或者创意实现你的网站,真正的建站仿站利器. The7的750+个主题设置 ...
- spring boot 集成 websocket 实现消息主动
来源:https://www.cnblogs.com/leigepython/p/11058902.html pom.xml 1 <?xml version="1.0" en ...