题意: 两个人比赛,给出比赛序列,如果为1,说明这场1赢,为2则2赢,假如谁先赢 t 盘谁就胜这一轮,谁先赢 s 轮则赢得整个比赛。求有多少种 t 和 s 的分配方案并输出t,s。

解法: 因为要知道有哪些t,s,那么我们至少要枚举一个量,然后才能得出所有分配方案,由题意似乎枚举 t 比较方便。由于 n <= 10^5, 那么我们必须在平均logn算法级以下判断此 t 合不合法,即有没有合法的 s 。经过一些预处理,或者二分都可以达到logn的算法。

预处理sum1[i], sum2[i] 分别表示 i 的左边有多少个1和2.

容器K1,K2分别记录第 i 个1和第 i 个2出现的位置。

然后我们每次扫过去,得出每一轮谁先赢,然后判断最后两个人赢的轮数来得出答案,如果最后是X赢,那么X赢得盘数就要大于另外一个,否则此 t 不合法。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define N 100007 vector<pair<int,int> > ans;
vector<int> K1,K2;
int sum1[N],sum2[N],a[N]; int main()
{
int n,i,j,t,s;
while(scanf("%d",&n)!=EOF)
{
ans.clear(), K1.clear(), K2.clear();
for(i=;i<=n;i++) cin>>a[i];
sum1[] = sum2[] = ;
int T1 = , T2 = ;
for(i=;i<=n;i++)
{
sum1[i] = T1, sum2[i] = T2; //0~i-1
if(a[i] == ) K1.push_back(i), T1++;
else K2.push_back(i), T2++;
}
for(t=;t<=n;t++) //t
{
int pos = , won1 = , won2 = , last = ;
while(pos <= n)
{
int c1 = sum1[pos], c2 = sum2[pos];
if(c1 + t > T1 && c2 + t > T2) break;
else if(c1 + t <= T1 && c2 + t <= T2)
{
if(K1[c1+t-] < K2[c2+t-]) //1先赢
{
won1++, last = ;
pos = K1[c1+t-];
}
else
{
won2++, last = ;
pos = K2[c2+t-];
}
}
else if(c1 + t <= T1) //2已经不可能赢
{
won1++, last = ;
pos = K1[c1+t-];
}
else if(c2 + t <= T2)
{
won2++, last = ;
pos = K2[c2+t-];
}
pos++;
}
if(pos == n+)
{
if((last==&&won1>won2) || (last==&&won1<won2))
ans.push_back(make_pair(max(won1,won2),t));
}
}
sort(ans.begin(),ans.end());
printf("%d\n",ans.size());
for(i=;i<ans.size();i++)
printf("%d %d\n",ans[i].first,ans[i].second);
}
return ;
}

Codeforces Round #283 Div.2 D Tennis Game --二分的更多相关文章

  1. Codeforces Round #283 (Div. 2) D. Tennis Game(模拟)

    D. Tennis Game time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  2. 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

    题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...

  3. 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

    题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...

  4. codeforces 497b// Tennis Game// Codeforces Round #283(Div. 1)

    题意:网球有一方赢t球算一场,先赢s场的获胜.数列arr(长度为n)记录了每场的胜利者,问可能的t和s. 首先,合法的场景必须: 1两方赢的场数不一样多. 2赢多的一方最后一场必须赢. 3最后一场必须 ...

  5. Codeforces Round #382 (Div. 2)C. Tennis Championship 动态规划

    C. Tennis Championship 题目链接 http://codeforces.com/contest/735/problem/C 题面 Famous Brazil city Rio de ...

  6. Codeforces Round #382 (Div. 2) C. Tennis Championship 斐波那契

    C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  7. Codeforces Round #382 (Div. 2) C. Tennis Championship

    C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  8. Codeforces Round #283 (Div. 2) C. Removing Columns 暴力

    C. Removing Columns time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #283 (Div. 2) A ,B ,C 暴力,暴力,暴力

    A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. Eclipse中的Web项目自动部署到Tomcat

    原因 很长时间没用Eclipse了,近期由于又要用它做个简单的JSP项目,又要重新学习了,虽然熟悉的很快,但记忆总是很模糊,偶尔犯错,以前很少写博客,现在感觉还是很有必要的,编程中每个人对于犯过的错误 ...

  2. Tomcat部署记事

    1.导入证书到jdk里 keytool -import -alias 证书名称 -file 证书地址 -keystore 导入位置 例:keytool -import -alias co3 -file ...

  3. SharePoint Error - An unrecognized HTTP response was received when attempting to crawl this item

    SharePoint 2013爬网报错 An unrecognized HTTP response was received when attempting to crawl this item. V ...

  4. ArcGIS Server 10.1发布数据源为ArcSDE(直连)的MXD【转】

    因为ArcSDE10.1基本默认直连,所以我们在发布直连的MXD仍然需要注意相关的事宜. 1:保证两台机器都能够访问共享存储的信息 2:确保已UNC路径保存ArcCatalog的文件夹连接,而且直连的 ...

  5. The specified file or folder name is too long

    You receive a "The specified file or folder name is too long" error message when you creat ...

  6. yii redies 不同的工程缓存key的问题

    参考这篇文章 基本配置操作: yii main.php中: return array( ... 'components'=>array( 'redis_cache' => array ( ...

  7. android 浅谈Aidl 通讯机制

    服务端: 首先是编写一个aidl文件,注意AIDL只支持方法,不能定义静态成员,并且方法也不能有类似public等的修饰符:AIDL运行方法有任何类型的参数和返回值,在java的类型中,以下的类型使用 ...

  8. Android微信登陆

    前言 分享到微信朋友圈的功能早已经有了,但微信登录推出并不久,文档写的也并不是很清楚,这里记录分享一下. 声明 欢迎转载,但请保留文章原始出处:)  博客园:http://www.cnblogs.co ...

  9. iOS 学习 - 10下载(2) NSURLSession 图片 篇

    使用NSURLSessionDownloadTask下载文件的过程与前面差不多,需要注意的是文件下载文件之后会自动保存到一个临时目录,需要开发人员自己将此文件重新放到其他指定的目录中. // // V ...

  10. [转]android笔记--Intent和IntentFilter详解

    Intent用于启动Activity, Service, 以及BroadcastReceiver三种组件, 同时还是组件之间通信的重要媒介. 使用Intent启动组件的优势1, Intent为组件的启 ...