枚举t加二分判断当前t是否可行,同时求出s。
注意不能说|a[n]| <= |3-a[n]|就证明无解,开始就是wa在这儿了。
可以简单想象成每当a[n]赢的时候,两人都打的难解难分(仅多赢一轮);而每当a[n]输的时候,一轮都没赢。
在这个前提下,显然存在|a[n]| <= |3-a[n]|。

 /* 283D */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxn = 1e5+;
int a[maxn];
int cnt[][maxn];
int n;
int id; int calc(int t) {
int i, j, p, q;
int c[];
int b[]; b[] = b[] = ;
c[] = c[] = ;
p = ;
while () {
i = lower_bound(cnt[]+p, cnt[]++n, c[]+t) - (cnt[]);
j = lower_bound(cnt[]+p, cnt[]++n, c[]+t) - (cnt[]);
if (cnt[][i]-c[]!=t && cnt[][j]-c[]!=t)
return ;
if (i < j) {
// 1 win
q = ;
++b[];
p = i;
} else {
q = ;
++b[];
p = j;
}
c[] = cnt[][p];
c[] = cnt[][p];
if (p >= n)
break;
} if (p != n)
return ; int id_ = - id;
if (b[id_]>=b[id] || q!=id)
return ;
return b[id];
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int c[]; scanf("%d", &n);
c[] = c[] = ;
rep(i, , n+) {
scanf("%d", &a[i]);
++c[a[i]];
cnt[a[i]][i] = cnt[a[i]][i-] + ;
cnt[-a[i]][i] = cnt[-a[i]][i-];
}
cnt[][n+] = cnt[][n+] = INT_MAX; id = a[n];
int an = c[id], bn = c[]+c[]-an; // if (an <= bn) {
// puts("0");
// return 0;
// } int i, j;
vpii ans; for (i=; i<=n; ++i) {
j = calc(i);
if (j)
ans.pb(mp(j, i));
} sort(all(ans)); n = SZ(ans);
printf("%d\n", n);
rep(i, , n) {
printf("%d %d\n", ans[i].fir, ans[i].sec);
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【CF】283D Tennis Game的更多相关文章

  1. 【CF】438E. The Child and Binary Tree

    http://codeforces.com/contest/438/problem/E 题意:询问每个点权值在 $c_1, c_2, ..., c_m$ 中,总权值和为 $s$ 的二叉树个数.请给出每 ...

  2. 【CF】148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个.当龙取完后,会等概率跳出一只.(0<= ...

  3. 【CF】328 D. Super M

    这种图论题已经变得简单了... /* D */ #include <iostream> #include <string> #include <map> #incl ...

  4. 【CF】323 Div2. D. Once Again...

    挺有意思的一道题目.考虑长度为n的数组,重复n次,可以得到n*n的最长上升子序列.同理,也可以得到n*n的最长下降子序列.因此,把t分成prefix(上升子序列) + cycle(one intege ...

  5. 【CF】7 Beta Round D. Palindrome Degree

    manacher+dp.其实理解manacher就可以解了,大水题,dp就是dp[i]=dp[i>>1]+1如何满足k-palindrome条件. /* 7D */ #include &l ...

  6. 【CF】86 B. Petr#

    误以为是求满足条件的substring总数(解法是KMP分别以Sbeg和Send作为模式串求解满足条件的position,然后O(n^2)或者O(nlgn)求解).后来发现是求set(all vali ...

  7. 【CF】121 Div.1 C. Fools and Roads

    题意是给定一棵树.同时,给定如下k个查询: 给出任意两点u,v,对u到v的路径所经过的边进行加计数. k个查询后,分别输出各边的计数之和. 思路利用LCA,对cnt[u]++, cnt[v]++,并对 ...

  8. 【CF】310 Div.1 C. Case of Chocolate

    线段树的简单题目,做一个离散化,O(lgn)可以找到id.RE了一晚上,额,后来找到了原因. /* 555C */ #include <iostream> #include <str ...

  9. 【CF】110 Div.1 B. Suspects

    这题目乍眼一看还以为是2-sat.其实很水的,O(n)就解了.枚举每个人,假设其作为凶手.观察是否满足条件.然后再对满足的数目分类讨论,进行求解. /* 156B */ #include <io ...

随机推荐

  1. 类库探源——System.Math 和 Random

    一.System.Math Math类:为三角函数.对数函数和其他通用数学函数提供常数和静态方法 命名空间: System 程序集 :   mscorlib.dll 继承关系: 常用属性: Math. ...

  2. java新手笔记18 类比较

    1.Shap类 package com.yfs.javase; public class Shape /*extends Object */{ //默认继承object object方法全部继承 // ...

  3. 数学符号π (Pi)、Σ(Capital Sigma)、μ (Mu) 、σ(sigma)、∏(capital pi), ∫(Integral Symbol)的来历

    1.π (Pi; periphery/周长) March 14 marks Pi Day, the holiday commemorating the mathematical constant π ...

  4. Poj 3061 Subsequence(二分+前缀和)

    Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12333 Accepted: 5178 Descript ...

  5. 【C++11】新特性——Lambda函数

    本篇文章由:http://www.sollyu.com/c11-new-lambda-function/ 文章列表 本文章为系列文章 [C++11]新特性--auto的使用 http://www.so ...

  6. 解决读写properties属性文件

    package com.kzkj.wx.utils; import java.io.BufferedReader; import java.io.File; import java.io.FileIn ...

  7. react native学习1-安装,执行

    demo地址 http://www.oschina.net/p/reactnative http://my.oschina.net/luyongfugx/blog/394427#OSC_h1_1 翻译 ...

  8. Avoiding “will create implicit index” NOTICE

    执行PgSql避免 notice 信息,执行之前加入以下语句调整报错级别即可: SET CLIENT_MIN_MESSAGES = ‘WARNING’;

  9. nslookup命令详解

    Nslookup 是一个监测网络中DNS服务器是否能正确实现域名解析的命令行工具.它在 Windows NT/2000/XP(在之后的windows系统也都可以用的,比如win7,win8等) 中均可 ...

  10. 针对IE的CSS hack 全面 实用

    .all IE{property:value\9;} .gte IE 8{property:value\0;} .lte IE 7{*property:value;} .IE 8/9{property ...