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 ...
随机推荐
- AndroidManifest具体解释之Application(有图更好懂)
可以包括的标签: <activity> <activity-alias> <service> <receiver> <provider> & ...
- kubernetes调度之资源耗尽处理配置
系列目录 本篇将介绍如何使用kubelet处理资源耗尽的情况 当可用的计算机资源非常低的时候,kubelet仍然要保证节点的稳定性.当处理不可压缩的计算机资源(比如内存或磁盘空间)时,这尤其重要,当这 ...
- C#注冊表操作汇总
一.注冊表基本知识 1) 结构 键->项->子项->值项(名称.类型.数据) REG_SZ 字符串 REG_BINARY 二进制 REG_DWORD ...
- PHP对称加密类
<?php /** * Created by PhpStorm. * User: zongbinghuang * Date: 2017/7/31 * Time: 15:13 */ namespa ...
- Geeks LCA最低公共单亲节点
给出一颗二叉树.找到两个值的最小公共节点. 假设两个值都会在树中出现. 假设可能不会出现的话,也非常easy.就查找一遍看两个值是否在树中就能够了.假设不在就直接返回NULL. 基本思想:就是在二叉树 ...
- hdu5258简单枚举
百度之星复赛第一题.不明白这么水的题为何一堆人没过...这些人是咋晋级复赛的呢... /* * Author : ben */ #include <cstdio> #include < ...
- 九度OJ 1113:二叉树 (完全二叉树)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5079 解决:1499 题目描述: 如上所示,由正整数1,2,3--组成了一颗特殊二叉树.我们已知这个二叉树的最后一个结点是n.现在的问题是 ...
- 九度OJ 1089:数字反转 (数字反转)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3059 解决:1678 题目描述: 12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个 ...
- Hackerspace
Hackerspace Software - HackerspaceWiki https://wiki.hackerspaces.org/Hackerspace_Software Hackerspac ...
- 一篇文章搞明白CORS跨域
面试问到数据交互的时候,经常会问跨域如何处理.大部分人都会回答JSONP,然后面试官紧接着就会问:"JSONP缺点是什么啊?"这个时候坑就来了,如果面试者说它支持GET方式,然后面 ...