大意: 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);
}
}

Voting CodeForces - 749C (set,模拟)的更多相关文章

  1. Voting CodeForces - 749C

    有点意思的题 Voting CodeForces - 749C 题意:有n个人投票,每次按照第1个人~第n个人的顺序发言,如果到某个人发言时他已经被禁止发言就跳过,每个人发言时可以禁止另一个人发言或什 ...

  2. Codeforces 749C【模拟】

    FST的时候好像挂了挺多人的~ 其实思路没啥难的,就是更好地理解题意吧,1到n一直循环,直到没有人能vote,一个人能vote也能叉掉一个人,一个人被叉就不能vote,判谁赢. 其实我管vote干嘛, ...

  3. Codeforces 749C:Voting(暴力模拟)

    http://codeforces.com/problemset/problem/749/C 题意:有n个人投票,分为 D 和 R 两派,从1~n的顺序投票,轮到某人投票的时候,他可以将对方的一个人K ...

  4. Codeforces 749C. Voting 模拟题

    C. Voting time limit per test: 1 second memory limit per test: 256 megabytes input: standard input o ...

  5. CodeForces - 749C Voting

    C. Voting time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  6. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  7. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  8. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  9. Codeforces 631C. Report 模拟

    C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

随机推荐

  1. ClientScriptManager 和 ScriptManager RegisterClientScriptBlock

    ClientScriptManager.RegisterOnSubmitStatement(Type, String, String) Method Registers an OnSubmit sta ...

  2. spark 源码编译 standalone 模式部署

    本文介绍如何编译 spark 的源码,并且用 standalone 的方式在单机上部署 spark. 步骤如下: 1. 下载 spark 并且解压 本文选择 spark 的最新版本 2.2.0 (20 ...

  3. leetcode-easy-trees-Maximum Depth of Binary Tree

    mycode  92.69% # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x ...

  4. DeepFaceLab错误:DLL Load failed 找不到指定模块!

    这个错误不知道多少人遇到了,我反正是看到过不少次了.但是一直没有花时间去研究. 今日有空帮群友远程了一下,虽然搞了一会儿,最终还是搞定了,分享一下经验. ​ 问题描述:在执行2号脚本,视频转图片的时候 ...

  5. 由MySQL登录不了引发的一些问题

    经手的项目按照老板的意思,想搞一个类似于个人学习版的版本给客户试用.计划通过网络将安装包发布出去,让客户自行下载安装使用,碰到个问题:数据库的安装.因为后台使用了MS SQLServer 2008/2 ...

  6. 关于Oracle报表

    1.存储过程中的WHEN OTHERS THEN是什么意思. 异常分很多种类,如NO_FOUND.OTHERS处本应该写异常名称,如果不想把异常分得那么细,可以笼统一点用OTHERS来捕获,即所有异常 ...

  7. 集成ShareSdk一键分享和第三方登录

    在Mob官网http://mob.com/注册,创建应用,下载SDK,申请APP_key 根据官网开发指南导入SDK到你的项目中: 在assets/ShareSDk.xml中修改你的APP_key p ...

  8. 基于form表单的极验滑动验证小案例

    01.目录展示 02.url.py urlpatterns = [ path('admin/', admin.site.urls), path('login/',views.login), path( ...

  9. Python基本语法_控制流语句_if/while/for

    目录 目录 前言 软件环境 If 语句 While循环 break continue for 循环 遍历String 遍历Tuple 遍历List 遍历Dictionary 最后 前言 控制流语句用于 ...

  10. nginx禁止指定的user_agent访问

    #禁止指定user_agent(浏览器标识)if ($http_user_agent ~ 'curl|baidu'){ return 403;} if ($http_user_agent ~* 'cu ...