大意: n个人, 两个党派, 轮流投票, 两种操作(1)ban掉一个人 (2)投票, 每轮一个未被ban的人可以进行一次操作(1)或操作(2), 求最终哪个党派得票最多.

显然先ban人会更优, 所以维护两个set模拟. 不过好像可以有O(n)的做法?

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e6+10;
int n, a[N];
char s[N], b[2][2]{"R","D"};
set<int> q, g[2]; int main() {
scanf("%d%s", &n, s);
REP(i,0,n-1) {
a[i]=s[i]=='D';
q.insert(i);
g[a[i]].insert(i);
}
REP(i,0,1) if (g[!i].empty()) return puts(b[i]),0;
while (q.size()) {
int x = *q.begin(); q.erase(x);
int id = a[x%n], now = x/n;
auto t = g[!id].lower_bound(x%n);
if (t==g[!id].end()) t=g[!id].begin(),++now;
q.erase(now*n+*t);
g[!id].erase(t);
if (g[!id].empty()) return puts(b[id]),0;
q.insert(x+n);
}
}

最新文章

  1. [No000097]程序员面试题集【下】
  2. HTML 学习笔记 JavaScript(面向对象)
  3. MOOCULUS微积分-2: 数列与级数学习笔记 4. Alternating series
  4. 机器学习六--K-means聚类算法
  5. python学习之操作mysql
  6. ASP.NET网页生成EXCEL并下载(利用DataGrid或GridView等)
  7. [转]EntityFramework走马观花之CRUD(中)
  8. WEB ui快速构建
  9. 再回首,Java温故知新——开篇说明
  10. wIndows phone 7 解析Html数据
  11. 25+免费的Bootstrap HTML5网站模板
  12. Docker - 访问容器
  13. ViewPager无限轮播与自定义切换动画
  14. asp.net core 依赖注入几种常见情况
  15. 转:RowVersion 用法
  16. Ruby页面,循环赋值方法(类似java EL表达式赋值)
  17. EOS.IO Technical White Paper v2
  18. PHP学习和使用总结
  19. 重构改善既有代码设计--重构手法16:Introduce Foreign Method (引入外加函数)&amp;&amp; 重构手法17:Introduce Local Extension (引入本地扩展)
  20. 【iOS开发】 AudioSession设置, 切换扬声器和听筒详解-保留其他应用音乐(备忘)

热门文章

  1. JS框架_(JQuery.js)纯css3进度条动画
  2. 运算 Kotlin(3)
  3. wordpress 更新时需要FTP 服务器账户密码的解决方法
  4. CSS - 架构
  5. 十一:jinja2模板传参
  6. vue中html、css、js 分离
  7. Elasticsearch 6.2.3版本 同一个index新增type报错 Rejecting mapping update to [website] as the final mapping would have more than 1 type: [blog2, blog]
  8. 微信小程序---绘图
  9. JavaScript Source Maps浅析
  10. yum升级python