题意:进行若干场比赛,每次比赛两人对决,赢的人得到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 (暴力枚举)的更多相关文章

  1. Codeforces 496D - Tennis Game

    496D - Tennis Game 思路:枚举每个t,求出对应的满足条件的s. 代码: #include<bits/stdc++.h> using namespace std; #def ...

  2. Codeforces 626E Simple Skewness(暴力枚举+二分)

    E. Simple Skewness time limit per test:3 seconds memory limit per test:256 megabytes input:standard ...

  3. codeforces Restore Cube(暴力枚举)

    /* 题意:给出立方体的每个顶点的坐标(是由源坐标三个数某几个数被交换之后得到的!), 问是否可以还原出一个立方体的坐标,注意这一句话: The numbers in the i-th output ...

  4. codeforces 700C Break Up 暴力枚举边+边双缩点(有重边)

    题意:n个点,m条无向边,每个边有权值,给你 s 和 t,问你至多删除两条边,让s,t不连通,问方案的权值和最小为多少,并且输出删的边 分析:n<=1000,m是30000  s,t有4种情况( ...

  5. Diverse Garland CodeForces - 1108D (贪心+暴力枚举)

    You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...

  6. Codeforces 327A-Flipping Game(暴力枚举)

    A. Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  7. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  8. Tennis Game CodeForces - 496D(唯一分解定理,费马大定理)

    Tennis Game CodeForces - 496D 通过排列组合解决问题. 首先两组不同素数的乘积,是互不相同的.这应该算是唯一分解定理的逆运用了. 然后是,输入中的素数,任意组合,就是n的因 ...

  9. 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 ...

随机推荐

  1. TCP/IP协议组学习笔记

    TCP/IP协议族学习笔记: 一.基础概念: (1)TCP(Transmission Control Protocol) 传输控制协议. (2)IP(Internet Protocol)网际协议.IP ...

  2. [框架安装趟雷指南]Ubuntu+1060+cuda+cudnn+Keras+TH+TF+MXnet

    [框架安装趟雷指南]Ubuntu+1060+cuda+cudnn+Keras+TH+TF+MXnet https://zhuanlan.zhihu.com/p/23480983 天清 9 个月前 写这 ...

  3. MVC3-表单

    [.NET Core已取消]Html.BeginForm() 该方法用于构建一个From表单的开始,他的构造方法为:Html.BeginForm("ActionName", &qu ...

  4. eclipse的快捷键(常用)

    1. Ctrl+O 显示类中方法和属性的大纲,能快速定位类的方法和属性,在查找Bug时非常有用. 2. Ctrl+M 窗口最大化和还原,用户在窗口中进行操作时,总会觉得当前窗口小(尤其在编写代码时), ...

  5. ffmpeg api升级到3.3 api变化

     void av_free_packet(AVPacket * pkt) Use void av_packet_unref(AVPacket * pkt) Wipe the packet. Unref ...

  6. Kotlin基本语法笔记之函数、变量的定义及null检测

    定义函数 fun sum(a: Int, b: Int): Int { return a + b } 该函数中两个参数的类型都是Int,返回类型是Int 也可以做如下简化 fun sum(a: Int ...

  7. 2014-8-17 note

    一.方格求最短路径 二.用两种颜色去染排成一个圈的6个棋子,如果通过旋转得到则只算一种,一共有多少种染色模式 设两种颜色为黑白 全黑1种+全白1种=2 1黑5白(1种)+1白5黑(1种)=2种 2黑4 ...

  8. php高级技巧总结

    通过对<深入理解PHP:高级技巧.面向对象与核心技术>这本书的学习,总结出常用的php高级技巧,也方便自己以后查阅;我认为该书是php高级教程的葵花宝典,哈哈.里面的内容很实用,尤其是在项 ...

  9. [usaco2008feb_gold]路面修整

      FJ打算好好修一下农场中某条凹凸不平的土路.按奶牛们的要求,修好后的路面高度应当单调上升或单调下降,也就是说,高度上升与高度下降的路段不能同时出现在修好的路中. 整条路被分成了N段,N个整数A_1 ...

  10. pypi指定下载源

    pip install -i http://pypi.douban.com/simple/ scipy==0.19.0