B. Tennis Game
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores t points, he wins the set; then the next set starts and scores of both players are being set to 0. As soon as one of the players wins the total of s sets, he wins the match and the match is over. Here s and t are some positive integer numbers.

To spice it up, Petya and Gena choose new numbers s and t before every match. Besides, for the sake of history they keep a record of each match: that is, for each serve they write down the winner. Serve winners are recorded in the chronological order. In a record the set is over as soon as one of the players scores t points and the match is over as soon as one of the players wins s sets.

Petya and Gena have found a record of an old match. Unfortunately, the sequence of serves in the record isn't divided into sets and numbers s and t for the given match are also lost. The players now wonder what values of s and t might be. Can you determine all the possible options?

Input

The first line contains a single integer n — the length of the sequence of games (1 ≤ n ≤ 105).

The second line contains n space-separated integers ai. If ai = 1, then the i-th serve was won by Petya, if ai = 2, then the i-th serve was won by Gena.

It is not guaranteed that at least one option for numbers s and t corresponds to the given record.

Output

In the first line print a single number k — the number of options for numbers s and t.

In each of the following k lines print two integers si and ti — the option for numbers s and t. Print the options in the order of increasingsi, and for equal si — in the order of increasing ti.

Sample test(s)
input
5
1 2 1 2 1
output
2
1 3
3 1
input
4
1 1 1 1
output
3
1 4
2 2
4 1
input
4
1 2 1 2
output
0
input
8
2 1 2 1 1 1 1 1
output
3
1 6
2 3
6 1

只要暴力枚举每盘游戏的结束分数 t, 然后判断游戏的盘数 s 。

怎么判断s呢,当然就是找s的倍数 lar 。

然后再进行二分出两个玩家拿到结束当局游戏的分数 , 位置比较前的就是赢家 。

这题是我打那么多场DIV1最可惜的一题 , 卡在了边缘 。没有判断第n 个位置一定是要赢家得分的 。

而且注意 , 最后得分的人赢的游戏盘数一定比另外一个人多才符合要求 。

复杂度就是 n * log n * log n ( 枚举分数 t , 枚举 t 的倍数 , 二分 分数的位置 ) 。

#include <bits/stdc++.h>
using namespace std;
const int N = ;
const int INF = 1e9+;
typedef pair<int,int> pii;
#define X first
#define Y second
int n , a[N], cnt1[N] , cnt2[N] ;
vector<pii>ANS; int Find( int sc , int *A ) { int l = , r = n , pos = INF ;
if( A[n] < sc ) return pos;
while( l <= r ){
int mid = (l+r)>>;
if( A[mid] < sc )
l = mid + ;
else
pos = mid , r = mid - ;
}
return pos ;
} int check( int t ) { int ans = , sc1 = , sc2 = ;
int c1 = , c2 = ;
while( ){
int pos1 = Find( sc1 + t , cnt1 );
int pos2 = Find( sc2 + t , cnt2 );
if( pos1 == INF && pos2 == INF ) return - ;
if( pos1 == INF ) {
if( ( cnt2[n] - sc2 ) %t || a[n] == ) return - ;
else {
c2 += ( cnt2[n] - sc2 ) / t ;
if( c1 >= c2 ) return - ;
return c2 ;
}
}
if( pos2 == INF ) {
if( ( cnt1[n] - sc1 ) %t || a[n] == ) return - ;
else {
c1 += ( cnt1[n] - sc1 ) / t ;
if( c2 >= c1 ) return - ;
return c1 ;
}
}
if( pos1 < pos2 ) c1++ , sc1 = cnt1[pos1] , sc2 = cnt2[pos1];
else c2++ , sc1 = cnt1[pos2] , sc2 = cnt2[pos2] ;
}
} int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
while( cin >> n ){
cnt1[] = cnt2[] = ;
for( int i = ; i <= n ; ++i ) {
cin >> a[i] ;
if( a[i] == ) cnt1[i] = cnt1[i-]+ , cnt2[i] = cnt2[i-];
else cnt1[i] = cnt1[i-] , cnt2[i] = cnt2[i-]+;
}
int tot = max( cnt1[n] , cnt2[n] ) , ans = ;
ANS.clear();
for( int i = ; i <= tot ; ++i ) {
int res = check(i);
if( res != - ) {
ans++; ANS.push_back( pii( res , i ) );
}
}
sort( ANS.begin() , ANS.end() ) ;
cout << ans << endl ;
for( int i = ; i < ans ; ++i ) {
cout << ANS[i].X <<' ' << ANS[i].Y << endl ;
}
}
}

Codeforces 497B Tennis Game( 枚举+ 二分)的更多相关文章

  1. codeforces 613B B. Skills(枚举+二分+贪心)

    题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

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

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

  3. Codeforces C. Maximum Value(枚举二分)

    题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. HDU4430 Yukari's Birthday(枚举+二分)

    Yukari's Birthday  HDU4430 就是枚举+二分: 注意处理怎样判断溢出...(因为题目只要10^12) 先前还以为要用到快速幂和等比数列的快速求和(但肯定会超__int64) 而 ...

  5. CSU OJ PID=1514: Packs 超大背包问题,折半枚举+二分查找。

    1514: Packs Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 61  Solved: 4[Submit][Status][Web Board] ...

  6. 4 Values whose Sum is 0(枚举+二分)

    The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute ...

  7. Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分

    C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...

  8. Codeforces gym101612 L.Little Difference(枚举+二分)

    传送:http://codeforces.com/gym/101612 题意:给定一个数n(<=1e18),将n分解为若干个数的成绩.要求这些数两两之间的差值不能大于1. 分析: 若n==2^k ...

  9. Codeforces 734C Anton and Making Potions(枚举+二分)

    题目链接:http://codeforces.com/problemset/problem/734/C 题目大意:要制作n个药,初始制作一个药的时间为x,魔力值为s,有两类咒语,第一类周瑜有m种,每种 ...

随机推荐

  1. Panabit的各种配置文件

    Panabit的各种配置文件 1.启动配置文件路径:/etc/rc.local作用:这个文件里的内容是BSD启动后会自动执行的命令默认配置如下:fsck -y -t ufs /dev/ad0s2a & ...

  2. 2018-8-10-win10-uwp-毛玻璃

    title author date CreateTime categories win10 uwp 毛玻璃 lindexi 2018-08-10 19:16:50 +0800 2018-2-13 17 ...

  3. 靶场练习--sqli(1&2)

    前言 懒猪赵肥肥耍了3天3夜,每天除了练英语口语,啥子都没干.今天开始发愤图强,嘻嘻~ 计划内容有:靶场.视频.python.PHP.java.计算机英语. 首先,每天必搞靶场必看视频必学java和英 ...

  4. 微信小程序(18)-- 自定义头部导航栏

    最近做的项目涉及相应的页面显示相应的顶部标题,所以就需要自定义头部导航了. 首先新建一个顶部导航公用组件topnav,导航高度怎么计算? 1.wx.getSystemInfo 和 wx.getSyst ...

  5. vue,一路走来(15)--简单投票系统

    今天记录一下简单的投票系统,主要实现选中至少五张作品,并提交投票. 思路:选中作品,将作品id存入到数组里. 取消投票,则从数组中移除该作品id. 如图效果: <li v-for="( ...

  6. Mybatis 单表 常用增删改查

    1.编写sql表,插入原始数据 -- 删除表 DROP TABLE testA; -- 创建表 CREATE TABLE testA( id INT AUTO_INCREMENT PRIMARY KE ...

  7. 【LeetCode】从contest-21开始。(一般是10个contest写一篇文章)

    [LeetCode Weekly Contest 29][2017/04/23] 第17周 Binary Tree Tilt (3) Array Partition I (6) Longest Lin ...

  8. python 中 len()和range()

    https://blog.csdn.net/qq_36357820/article/details/77850841

  9. python-zmail发送邮件

    import zmail #发送测试报告到邮件 with open(r'F:\asus\auto_file\unittest_html\2019-06-30 10-31-03report.html', ...

  10. shell编程之基础知识1

    1.shell脚本的基本格式 #!bin/bash   ->看到这个就是shell脚本 #filename:test.sh ->脚本名称 #auto echo hello world -& ...