枚举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. 20160331javaweb之JSP include 指令&&九大隐式对象

    3.零散知识 (1)jsp映射 <servlet> <servlet-name>index</servlet-name> <jsp-file>/inde ...

  2. Jquery基础整理

    1.简单的JQuery (1)  $(document).ready(function(){ $(document).ready(mydays); alert(“加载完毕,请检查!”); functi ...

  3. #ifndef#define#endif的用法

    在网上看到了感觉作者总结得很好,作者辛苦了! #ifndef#define#endif的用法 文件中的#ifndef 头件的中的#ifndef,这是一个很关键的东西.比如你有两个C文件,这两个C文件都 ...

  4. swift-08-元组分解和数组

    //1.有时候需要把元组中的数据拆分出来使用比如: var stu = ("范冰冰",30,"女") // 1)将stu中的数据赋值给三个变量. var (na ...

  5. 如何在windows server 2008的桌面上显示 我的电脑

    装完windows server2008 r2 x64后发现桌面只有一个回收站图标,这一点和xp 20003都差不多,但是xp 2003很容易就把桌面上的 我的电脑 我的文档 网上邻居找到,但是win ...

  6. 使用ibatis时 sql中 in 的参数赋值

    一.问题描述: 1.在使用ibatis执行下面的sql: update jc_jiesuan set doing_time = unix_timestamp(curdate()),doing_stat ...

  7. Oracle 10g 默认安装带来的用户名/密码

    ORACLE数据库创建的时候,创建了一系列默认的用户和表空间 Oracle 10g 默认安装带来的用户名/密码 Username Password Description See Also CTXSY ...

  8. 使用CLK.AspNet.Identity提供以角色为基础的访问控制(RBAC)

    使用CLK.AspNet.Identity提供以角色为基础的访问控制(RBAC) 程序代码下载 程序代码下载:点此下载 前言 ASP.NET Identity是微软所贡献的开源项目,用来提供ASP.N ...

  9. 基于SSM框架的简易的分页功能——包含maven项目的搭建

    新人第一次发帖,有什么不对的地方请多多指教~~ 分页这个功能经常会被使用到,我之前学习的时候找了很多资源,可都看不懂(笨死算了),最后还是在朋友帮助下做出了这个分页.我现在把我所能想到的知识 做了一个 ...

  10. CCPC网络赛,HDU_5842 Lweb and String

    Problem Description Lweb has a string $S$. Oneday, he decided to transform this string to a new sequ ...