Codeforces Round #604 (Div. 2) A,B,C【D题待补】

思路:直接暴力判断就OK了
#include<bits/stdc++.h> using namespace std;
#define int long long signed main(){
int _;cin>>_;
while(_--){
string str;
cin>>str;
if(str.size()==){
if(str[]!='?'){
cout<<str<<'\n';
}else{
printf("a\n");
}
continue;
}
int flag=;
for(int i=;i<str.size();i++){
if(str[i]=='?'){
int temp1=;int temp2=;
if(i->=){
if(str[i-]=='a'){
temp1=;
}else if(str[i-]=='b'){
temp1=;
}else if(str[i-]=='c'){
temp1=;
}else{
temp1=-;
}
}
if(i+<str.size()){
if(str[i+]=='a'){
temp2=;
}else if(str[i+]=='b'){
temp2=;
}else if(str[i+]=='c'){
temp2=;
}else{
temp2=-;
}
}
if(temp1==-&&temp2==-){
str[i]='a';
}else if(temp1==temp2){
if(temp1==){
str[i]='b';
}else if(temp1==){
str[i]='a';
}else if(temp1==){
str[i]='a';
}
}else{
map<int,int> vis;
vis[temp1]=;
vis[temp2]=;
int F=;
for(int i=;i<=;i++){
if(!vis[i]){
F=i;
break;
}
}
if(F==){
str[i]='a';
}else if(F==){
str[i]='b';
}else if(F==){
str[i]='c';
}
}
}
}
for (int i=;i<str.size()-;i++){
if(str[i]==str[i+]){
flag=;
break;
}
}
if(flag){
cout<<"-1"<<'\n';
continue;
}else{
cout<<str<<'\n';
}
}
return ;
}

思路:经过观察发现,排序后只要每个数对应的id是连续的就符合条件。
#include<bits/stdc++.h>
#include<queue>
using namespace std;
#define int long long
#define N 1005000
#define inf 0x3f3f3f3f3f3f
struct str{
int num;
int id;
}st[N];
int ans[N];
bool cmp(str a,str b){
return a.num<b.num;
}
deque<int> q; // 维护最小值和最大值
signed main(){
int _;
cin>>_;
while(_--){
int n;
cin>>n;
ans[]=;
ans[n]=;
for(int i=;i<=n;i++){
scanf("%lld",&st[i].num);
st[i].id=i;
}
sort(st+,st++n,cmp);
/*
for(int i=1;i<=n;i++){
printf("%lld %lld\n",st[i].num,st[i].id);
}
*/
int minx=inf;
int maxn=(-)*inf;
minx=min(st[].id,minx);
maxn=max(maxn,st[].id);
for(int i=;i<n;i++){
minx=min(st[i].id,minx);
maxn=max(maxn,st[i].id);
int dis=;
dis=maxn-minx+;
if(i==dis){
ans[i]=;
}else{
ans[i]=;
} }
for(int i=;i<=n;i++) printf("%lld",ans[i]);
printf("\n");
for(int i=;i<=n+;i++){
ans[i]=;
st[i].id=;st[i].num=;
}
}
return ;
}

思路:题目对于g有大小限制而s和b之间没有,则我们让g尽可能小就好了,即选解题数最高的那一组选手全部发金牌,然后发银牌,直到g>s,剩下的选手全部发铜牌,直到发的牌数恰好小于n/2即可,做不到则不可行。【模拟一下】
#include<bits/stdc++.h> using namespace std;
#define int long long
#define N 1050025
#define inf 0x3f3f3f3f3f
int arr[N];
signed main(){
int _;cin>>_;
while(_--){
int n;
cin>>n;
int g=,s=,b=;
for(int i=;i<=n;i++){
scanf("%lld",&arr[i]);
}
if(n<){
cout<<"0 0 0\n";
continue;
}
int maxn_sum=n/;
int avg=maxn_sum/;
int sum_g=;int sum_s=;int sum_b=;
int now=;
for(int i=;i<=n&&i<=maxn_sum;i++,now++){
if(arr[i]==arr[i+]){
sum_g++;
}else{
break;
}
}
g=sum_g;
for(int i=now+;i<=n&&i<=maxn_sum;i++,now++){
if(sum_s<=sum_g){
sum_s++;
}else{
if(arr[i]==arr[i+]){
sum_s++;
}else{
break;
}
}
}
s=sum_s;
sum_b=maxn_sum-g-s;
b=sum_b;
if(sum_b<=g){
printf("0 0 0\n");
continue;
}
if(arr[maxn_sum]==arr[maxn_sum+]){
for(int i=maxn_sum;i>=;i--){
if(arr[i]==arr[i-]){
b--;
}else{
b--;
break;
}
}
}
if(b<=g||b<=||s<=||g<=||s<=g){
printf("0 0 0\n");
continue;
}else{
printf("%lld %lld %lld\n",g,s,b);
} }
return ;
}
D题待补。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Codeforces Round #604 (Div. 2) A,B,C【D题待补】的更多相关文章
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #604(Div. 2,
// https://codeforces.com/contest/1265/problem/D /* 感觉像是遍历的思维构造题 有思路就很好做的 可以把该题想象成过山车或者山峰...... */ # ...
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors
链接: https://codeforces.com/contest/1265/problem/E 题意: Creatnx has n mirrors, numbered from 1 to n. E ...
- Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)
链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest
链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers
链接: https://codeforces.com/contest/1265/problem/B 题意: You are given a permutation p=[p1,p2,-,pn] of ...
- Codeforces Round #604 (Div. 2) A. Beautiful String
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学
题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...
- Codeforces Round #604 (Div. 2) 部分题解
链接:http://codeforces.com/contest/1265 A. Beautiful String A string is called beautiful if no two con ...
随机推荐
- 2019秋季PAT甲级_C++题解
2019 秋季 PAT (Advanced Level) C++题解 考试拿到了满分但受考场状态和知识水平所限可能方法不够简洁,此处保留记录,仍需多加学习.备考总结(笔记目录)在这里 7-1 Fore ...
- 我的Vue朝圣之路1
1. Vue是什么? 1). 一位华裔前Google工程师开发的前端js库 2). 一个MVVM框架 3). 核心概念 * 数据绑定 ...
- idea多级目录不展开的问题
遇见了一个坑,idea新建的包,和它的上级包重叠在了一起,无法形成树状结构 原因呢,还是因为自己的不细心了,解决方案很简单,下面的是原情况 解决方案,点击左侧栏右上角的设置图表,注意看红框内 把第一行 ...
- C#中的Process类使用
有时候,用户在进行某个操作时,程序运行到某个阶段突然崩溃,我们需要让程序自动重启,重新执行用户之前的操作,当发现主程序还存在,就重启用户执行的附加程序.这时候Process就派上了用场. 控制台测试用 ...
- HBuilder 方便局域网访问调试
同一个局域网,通过IP不能访问我本地的项目,各种测试发现原来是防火墙的问题: 这里附上参考文档:内置web服务器被防火墙禁用导致预览和运行异常的解决方案
- emacs手动安装、解决不能使用中文输入法
emacs的安装 emacs的下载,解压 wget http://mirrors.ustc.edu.cn/gnu/emacs/emacs-25.3.tar.gz tar -zxf emacs-25.3 ...
- jq + 面向对象实现拼图游戏
jq + 面向对象实现拼图游戏 知识点 拖拽事件 es6面向对象 jquery事件 效果图 html: <div class="wraper"> <div cla ...
- 几种常见的Preference总结
DialogPreference共性 DialogPreference通用属性 说明 android:dialogIco 对话框的icon android:dialogLayout dialog的co ...
- Android ProGuard:代码混淆压缩
写这篇文章的目的 一直以来,在项目中需要进行代码混淆时每次都要去翻文档,很麻烦.也没有像写代码那样记得那么多.既然要查来查去,就不如自己捋一捋这个知识点了,被人写的终究还是别人的.所以自己去翻看了很多 ...
- Python学习日记(二) list操作
l = ['a','b','c','d',1,2,[3,'e',4]] 1.list.append() 在list的结尾新增一个新的元素,没有返回值,但会修改原列表 l.append(5) print ...