Voting CodeForces - 749C (set,模拟)
大意: 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,模拟)的更多相关文章
- Voting CodeForces - 749C
有点意思的题 Voting CodeForces - 749C 题意:有n个人投票,每次按照第1个人~第n个人的顺序发言,如果到某个人发言时他已经被禁止发言就跳过,每个人发言时可以禁止另一个人发言或什 ...
- Codeforces 749C【模拟】
FST的时候好像挂了挺多人的~ 其实思路没啥难的,就是更好地理解题意吧,1到n一直循环,直到没有人能vote,一个人能vote也能叉掉一个人,一个人被叉就不能vote,判谁赢. 其实我管vote干嘛, ...
- Codeforces 749C:Voting(暴力模拟)
http://codeforces.com/problemset/problem/749/C 题意:有n个人投票,分为 D 和 R 两派,从1~n的顺序投票,轮到某人投票的时候,他可以将对方的一个人K ...
- Codeforces 749C. Voting 模拟题
C. Voting time limit per test: 1 second memory limit per test: 256 megabytes input: standard input o ...
- CodeForces - 749C Voting
C. Voting time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- Codeforces 389B(十字模拟)
Fox and Cross Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submi ...
- codeforces 591B Rebranding (模拟)
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...
- Codeforces 626B Cards(模拟+规律)
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- Codeforces 631C. Report 模拟
C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
随机推荐
- Dynamic Web Module 2.3 change to 3.0 maven工程解决办法
pom.xml <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <a ...
- centos6 centos7 配置开机启动服务
centos 6 :使用chkconfig命令即可. 我们以apache服务为例: #chkconfig --add apache 添加nginx服务 #chkconfig apache on 开机自 ...
- ANR错误分析
链接1:https://www.cnblogs.com/xiyuan2016/p/6740623.html 链接2:https://www.jianshu.com/p/3959a601cea6
- C++如何限制对象在堆上或栈上生成
1,限制类的对象只能生成在栈上 将 operator new 各种原型设为私有 #include <iostream> class OnlyOnStack { public: OnlyOn ...
- leetcode-easy-listnode-206 reverse linked list
mycode 98.87 # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x ...
- python出现AttributeError: module ‘xxx’ has no attribute ‘xxx’错误时,两个解决办法
运行python程序时,也许会出现这样的错误:AttributeError: module ‘xxx’ has no attribute ‘xxx’: 解决该错误有两种方法 1.手动安装该模块 2.检 ...
- python安装的各种问题
在windows上安装python下载mis安装即可. 环境用elipse即可,需要下载pydev插件,配置解释器. 如需用到matplotlib,安装顺序为matplot,numpy,dateuti ...
- ControlTemplate in WPF —— ItemsControl
<ItemsControl Margin=" ItemsSource="{Binding Source={StaticResource myTodoList}}"& ...
- idea 编译 brooklin
gradle 项目导入 idea 之后,各种报错,run 不起来 手动加入各种依赖 配置启动类 指定 log4j.properties
- select框可编辑
$(function(){ $("#select").editableSelect({ //$("#select")为select框id effects: 's ...