【CF】283D Tennis Game
枚举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的更多相关文章
- 【CF】438E. The Child and Binary Tree
http://codeforces.com/contest/438/problem/E 题意:询问每个点权值在 $c_1, c_2, ..., c_m$ 中,总权值和为 $s$ 的二叉树个数.请给出每 ...
- 【CF】148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个.当龙取完后,会等概率跳出一只.(0<= ...
- 【CF】328 D. Super M
这种图论题已经变得简单了... /* D */ #include <iostream> #include <string> #include <map> #incl ...
- 【CF】323 Div2. D. Once Again...
挺有意思的一道题目.考虑长度为n的数组,重复n次,可以得到n*n的最长上升子序列.同理,也可以得到n*n的最长下降子序列.因此,把t分成prefix(上升子序列) + cycle(one intege ...
- 【CF】7 Beta Round D. Palindrome Degree
manacher+dp.其实理解manacher就可以解了,大水题,dp就是dp[i]=dp[i>>1]+1如何满足k-palindrome条件. /* 7D */ #include &l ...
- 【CF】86 B. Petr#
误以为是求满足条件的substring总数(解法是KMP分别以Sbeg和Send作为模式串求解满足条件的position,然后O(n^2)或者O(nlgn)求解).后来发现是求set(all vali ...
- 【CF】121 Div.1 C. Fools and Roads
题意是给定一棵树.同时,给定如下k个查询: 给出任意两点u,v,对u到v的路径所经过的边进行加计数. k个查询后,分别输出各边的计数之和. 思路利用LCA,对cnt[u]++, cnt[v]++,并对 ...
- 【CF】310 Div.1 C. Case of Chocolate
线段树的简单题目,做一个离散化,O(lgn)可以找到id.RE了一晚上,额,后来找到了原因. /* 555C */ #include <iostream> #include <str ...
- 【CF】110 Div.1 B. Suspects
这题目乍眼一看还以为是2-sat.其实很水的,O(n)就解了.枚举每个人,假设其作为凶手.观察是否满足条件.然后再对满足的数目分类讨论,进行求解. /* 156B */ #include <io ...
随机推荐
- Css3动画库收集
1.animate.css – 齐全的CSS3动画库 http://www.dowebok.com/98.html 2.Angular官方动画库 http://augus.github.io/ngAn ...
- Android----二维码开发
Android----二维码开发 本文为原创,转载请注明出处:http://www.cnblogs.com/xiaobaicai12138/p/5644244.html 一.工具 谷歌的zxing 不 ...
- EF中使用语句 或存储过程 查询(转)
EF中使用语句 或存储过程 查询 1.无参数查询 var model = db.Database.SqlQuery("select* from UserInfoes ").ToLi ...
- 10.08_逛逛OSC
(1)每天逛逛OSC是我的习惯了. JNative.JACOB.Shrinkwrap API? .Lua.WSO2 Identity Server .JBoss Forge.Bugzilla.Cou ...
- 加载jar文件输出class和method
package file import java.util.jar.JarEntry import java.util.jar.JarFile import org.junit.Test; class ...
- IOS 学习笔记 2015-04-03 OC-API-文件读写
// // WPFileHelper.m // OC-API-文件操作 // // Created by wangtouwang on 15/4/3. // Copyright (c) 2015年 w ...
- 远程mysql出现ERROR 1130 (HY000): Host '172.17.42.1' is not allowed to connect to this MySQL server
ERROR 1130: Host ***.***.***.*** is not allowed to connect to this MySQL server 说明所连接的用户帐号没有远程连接的权限, ...
- 如何在Ubuntu上创建及管理LXC容器?
将LXC安装到Ubuntu上 $ sudo apt-get install lxc 安装完毕之后,运行lxc-checkconifg工具,检查当前Linux内核支持LXC的情况.要是一切都已被启用,内 ...
- Jquery EasyUI中treegrid的中右键菜单和一般按钮同时绑定事件时的怪异事件
做个项目使用jquery easyui来做前端,也许是对此不是很熟悉,总是发现一些不可理解的事件. 主要源代码如下: <script type="text/javascript&qu ...
- jquery api 笔记(2) 事件 事件对象
事件 #1.resize() 缩放窗体:window.resizeTo(width, height); 并不是兼容做法. #2 .scroll() ->获取滚动条的位置: .scro ...