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 ...
随机推荐
- eclipse 导入web项目时常见错误
1. JavaWeb:报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java B ...
- python发送post请求上传文件,无法解析上传的文件
前言 近日,在做接口测试时遇到一个奇葩的问题. 使用post请求直接通过接口上传文件,无法识别文件. 遇到的问题 以下是抓包得到的信息: 以上请求是通过Postman直接发送请求的. 在这里可以看到消 ...
- 关于erlang反编译的东西
在查阅了相关文档,想了解erlang反编译的东西.当然,源码可以打包成可以获取源码的,也可以保护源码的. 在ebin下,如果没有或者找不到源码,可以进行反编译,由beam文件得到erl文件. 可以通过 ...
- 如何使Htm页面使用IE9文档模式
修改Htm页面的方法之一是,在Head->Title下添加<META http-equiv="X-UA-Compatible" content="IE=9&q ...
- TEA对称加密算法
今天在看<Distributed Systems Concepts and Design>这本书的时候,在讲到分布式系统的安全性的时候,给出了TEA算法,书本上有现成的代码,所以摘录下来以 ...
- cocos2d-js v3事件管理器
总概: 1.时间监听器(cc.EventListener)封装用户的事件处理逻辑. 2.事件管理器(cc.eventManager)管理用户注册的事件监听器. 3.事件对象(cc.Event)包含事件 ...
- 【智能无线小车系列十】通过USB摄像头实现网络监控功能
如果仅有静态图像可能还不足以满足我们的需求,我们可能会需要用到实时的监控功能.这里介绍一款小应用:motion.motion的功能可强大了,不仅可以将监控的画面通过视频传输,实时展现,更为强大的是,m ...
- return;测试
一 没有return;,则会顺序执行到最后 <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...
- Codeforces Round #394 (Div. 2) B. Dasha and friends —— 暴力 or 最小表示法
题目链接:http://codeforces.com/contest/761/problem/B B. Dasha and friends time limit per test 2 seconds ...
- idea提交新项目到远程git创库
1.创建远程版本库 http://192.168.28.130:81 登陆用户:maohx/123456 版本库名称最后与本地项目名称一致 如:spring-cloud-demo 2.创建本地版本库 ...