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 ...
随机推荐
- python学习67-面向对象-封装
封装 1.什么是封装? 根据名字寓意为:把一个东西装起来,然后密封,类似这样的面向对象的编程为封装. 真正的封装是明确的区别内外,只能在内部用,外部无法调用. 2. 举例: class Car: _s ...
- hyper-v安装windows7
win7镜像下载地址 http://msdn.itellyou.cn/ 该网站都是微软系列的正规软件 非常好用 在hyper-v 虚拟机安装windows系统时,到百度搜索了几个iso 都不好用 到h ...
- iview 表格随着更改刷新
使用location.reload() 或者是 路由的 this.$router.go(0) 进行刷新的时候,是会出现一阵的空白区域的,因为是整个页面的刷新 ,所以比较缓慢,因此使用了provide/ ...
- Nginx惊群问题
Nginx惊群问题 "惊群"概念 所谓惊群,可以用一个简单的比喻来说明: 一群等待食物的鸽子,当饲养员扔下一粒谷物时,所有鸽子都会去争抢,但只有少数的鸽子能够抢到食物, 大部分鸽子 ...
- Spring Boot异步发送邮件和请求拦截器配置
用户登录流程图: 在spring拦截器中进行鉴权操作: 控制器的拦截: import com.mooc.house.common.model.User; import org.springframew ...
- CCF 2016-04-1 折点计数
CCF 2016-04-1 折点计数 题目 问题描述 给定n个整数表示一个商店连续n天的销售量.如果某天之前销售量在增长,而后一天销售量减少,则称这一天为折点,反过来如果之前销售量减少而后一天销售量增 ...
- 直线DDA,直线和圆的Bresenham算法
// DDA.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<Windows.h> #include<g ...
- 关闭 禁止 window10 UpdateOrchestrator UsoSvc服务
背景故事:w10流氓更新关了! 然后重启还更新? 读者肯定关过win10自动跟新服务 如图: 然后 还有这个流氓设置 然而微软还有一招啊! 前有win10 update 后有计划任务 powershe ...
- 7 批量查询mget、批量修改bulk
注意:当执行多条数据查询.增删改时,一定要用mget.bulk,提升性能,减少网络传输 mget 回顾:查询单个文档 GET /beauties/my/2 mget 查询多个文档: 不同 ...
- iOS - 动态库上架瘦身(去调虚拟机架构),不然验证会报错。
eg: localhost:改造 M.emor.Y$ lipo WebRTC.framework/WebRTC -thin armv7 -output WebRTC_armv7localhost:改造 ...