CodeForces 496D Tennis Game (暴力枚举)
题意:进行若干场比赛,每次比赛两人对决,赢的人得到1分,输的人不得分,先得到t分的人获胜,开始下场比赛,某个人率先赢下s场比赛时,
游戏结束。现在给出n次对决的记录,问可能的s和t有多少种,并按s递增的方式输出。
析:如果枚举s 和 t,那么一定会超时的,所以我们考虑是不是可以不用全枚举。我们只要枚举 t ,然后每次都去计算 s。
首先我们先预处理两个人的获得第 i 分时是第几场比赛。然后每次枚举每个 t,每次我们都是加上t,所以总的时间复杂度为 n*logn。
完全可以接受,注意有几个坑,首先是数组不要越界,因为在t 比较大的时候,可能会超数组上限,再就是最后要判断是不是在最后一场结束时,
正好决出胜负,如果是提前决出胜负,那么也不是符合。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 2e5 + 10;
const int mod = 1e6;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
vector<P> v;
int a[maxn], b[maxn]; int main(){
while(scanf("%d", &n) == 1){
v.clear();
int cnt1 = 0, cnt2 = 0;
memset(a, INF, sizeof a);
memset(b, INF, sizeof b);
for(int i = 1; i <= n; ++i){
scanf("%d", &m);
if(m == 1) a[++cnt1] = i;
else b[++cnt2] = i;
}
for(int t = 1; t <= n; ++t){
int i = 0, l = 0, r = 0;
cnt1 = 0, cnt2 = 0;
int c = 0;
while(i < n){
if(a[t+l] < b[t+r]){
i = a[t+l];
l += t;
r = i - l;
++cnt1; c = cnt1;
}
else {
i = b[t+r];
r += t;
l = i - r;
++cnt2; c = cnt2;
}
}
if(i == n && cnt1 != cnt2 && max(cnt1, cnt2) == c) v.push_back(P(c, t));
}
sort(v.begin(), v.end());
printf("%d\n", v.size());
for(int i = 0; i < v.size(); ++i)
printf("%d %d\n", v[i].first, v[i].second);
}
return 0;
}
CodeForces 496D Tennis Game (暴力枚举)的更多相关文章
- Codeforces 496D - Tennis Game
496D - Tennis Game 思路:枚举每个t,求出对应的满足条件的s. 代码: #include<bits/stdc++.h> using namespace std; #def ...
- Codeforces 626E Simple Skewness(暴力枚举+二分)
E. Simple Skewness time limit per test:3 seconds memory limit per test:256 megabytes input:standard ...
- codeforces Restore Cube(暴力枚举)
/* 题意:给出立方体的每个顶点的坐标(是由源坐标三个数某几个数被交换之后得到的!), 问是否可以还原出一个立方体的坐标,注意这一句话: The numbers in the i-th output ...
- codeforces 700C Break Up 暴力枚举边+边双缩点(有重边)
题意:n个点,m条无向边,每个边有权值,给你 s 和 t,问你至多删除两条边,让s,t不连通,问方案的权值和最小为多少,并且输出删的边 分析:n<=1000,m是30000 s,t有4种情况( ...
- Diverse Garland CodeForces - 1108D (贪心+暴力枚举)
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...
- Codeforces 327A-Flipping Game(暴力枚举)
A. Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举
题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...
- Tennis Game CodeForces - 496D(唯一分解定理,费马大定理)
Tennis Game CodeForces - 496D 通过排列组合解决问题. 首先两组不同素数的乘积,是互不相同的.这应该算是唯一分解定理的逆运用了. 然后是,输入中的素数,任意组合,就是n的因 ...
- Codeforces Round #298 (Div. 2) B. Covered Path 物理题/暴力枚举
B. Covered Path Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/probl ...
随机推荐
- 一步一步教你在 Android 里创建自己的账号系统(一)
大家假设喜欢我的博客,请关注一下我的微博,请点击这里(http://weibo.com/kifile),谢谢 转载请标明出处(http://blog.csdn.net/kifile),再次感谢 大家在 ...
- input 的read only 和 disable的区别
read only ---------->只能读,不能操作,但是数据可以提交 disable -------------->控件被禁用,数据不能提交
- mysql "ON DUPLICATE KEY UPDATE" 语法
如果在INSERT语句末尾指定了ON DUPLICATE KEY UPDATE,并且插入行后会导致在一个UNIQUE索引或PRIMARY KEY中出现重复值,则在出现重复值的行执行UPDATE:如果不 ...
- JAVA RMI远程方法调用简单实例(转载)
来源:http://www.cnblogs.com/leslies2/archive/2011/05/20/2051844.html RMI的概念 RMI(Remote Method Invocati ...
- UML类图组成
本文转载至 http://blog.csdn.net/fengsh998/article/details/8105666 UML类图的相关知识,UML类图(Classdiagram)是最常用的 ...
- 问题 “cell 出栈 selectBox 已选的图标,被释放掉,再次进入屏幕时,没有了已选图标 ” 解决方案
如何 去解决 列表里面的selectBox已选情况,在滑出屏幕后被清除的问题. 我来在这里 详细说明一下, 在cell里面写一个方法,去专门修复滑出后,又滑进来 图标被冲刷掉的cell. 在 ...
- 【BZOJ1844/2210】Pku1379 Run Away 模拟退火
[BZOJ1844/2210]Pku1379 Run Away 题意:矩形区域中有一堆点,求矩形中一个位置使得它到所有点的距离的最小值最大. 题解:模拟退火的裸题,再调调调调调参就行了~ #inclu ...
- keybd_event、SendInput笔记
void keybd_event(BYTE bVk, BYTE bScan, DWORD dwFlags, ULONG_PTR dwExtraInfo); bVk:虚拟键码 bScan:键的硬件扫描码 ...
- 自定义fragmentlayout
一.抽取视图文件,实例化需要在xml文件中 先上效果图: 1. 编写 xml布局文件 <?xml version="1.0" encoding="utf-8&qu ...
- Shell中括号的作用
Shell中括号的作用 作者:Danbo 时间:2015-8-7 单小括号() ①.命令组.括号中的命令将会断开一个子Shell顺序执行,所以括号中的变量不能被脚本余下的部分使用.括号中多个命令之间用 ...