Codeforces水题集合[14/未完待续]
Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework
模拟
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
ll l1,r1,l2,r2,k;
int main(int argc, const char * argv[]) {
cin>>l1>>r1>>l2>>r2>>k;
ll l=max(l1,l2),r=min(r1,r2);
ll ans=r-l+;
if(k>=l&&k<=r) ans--;
if(ans<) cout<<;
else cout<<ans;
return ;
}
YES最多三个数,成等差数列
分情况讨论
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
inline int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,a,cnt=,t[];
int main(int argc, const char * argv[]) {
n=read();
for(int i=;i<=n;i++){
a=read();
int flag=;
for(int j=;j<=cnt;j++)
if(a==t[j]){flag=;break;}
if(cnt==&&flag==){cout<<"NO";return ;}
if(cnt<&&flag==) t[++cnt]=a;
}
if(cnt<){cout<<"YES";return ;}
sort(t+,t++);
if(t[]-t[]==t[]-t[]) printf("YES");
else printf("NO");
return ;
}
Codeforces#372(Div.2)716A. Crazy Computer |716B. Complete the Word[模拟]
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,c,a,ans=,last=;
int main(int argc, const char * argv[]) {
n=read();c=read();
last=read();ans=;
for(int i=;i<=n;i++){
a=read();
if(a-last<=c){last=a;ans++;}
else {last=a;ans=;}
}
printf("%d",ans);
return ;
}
可以枚举n然后扫26个,也可以用队列糊O(n)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=5e4+;
char s[N];
int n,flag=,lst[],vis[],cnt=,st,ed; int main(int argc, const char * argv[]) {
scanf("%s",s+);
n=strlen(s+);
if(n<){printf("-1");return ;}
for(int i=;i<=n-;i++){
memset(vis,,sizeof(vis));
flag=;cnt=;
for(int j=i;j<=i+;j++)
if(s[j]!='?'){
int a=s[j]-'A';
if(vis[a]){flag=;break;}
vis[a]=;
}
if(flag){st=i;ed=i+;break;}
}
if(!flag){printf("-1");return ;}
memset(vis,,sizeof(vis));
for(int i=st;i<=ed;i++) if(s[i]!='?') vis[s[i]-'A']=;
for(int i=;i<;i++) if(!vis[i]) lst[++cnt]=i;
int p=;
for(int i=st;i<=ed;i++) if(s[i]=='?') s[i]=lst[++p]+'A';
for(int i=;i<=n;i++){
if(s[i]=='?') printf("A");
else printf("%c",s[i]);
}
return ;
}
Codeforces#373(Div.2)719A. Vitya in the Countryside |719B. Anatoly and Cockroaches[模拟]
1 second
256 megabytes
standard input
standard output
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.
Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.
As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.
The first line of the input contains a single integer n (1 ≤ n ≤ 92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.
The second line contains n integers ai (0 ≤ ai ≤ 15) — Vitya's records.
It's guaranteed that the input data is consistent.
If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1.
5
3 4 5 6 7
UP
7
12 13 14 15 14 13 12
DOWN
1
8
-1
In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".
In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".
In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
很水的模拟,注意0的话一定升,15的话一定降,单个也可以。
因为这个被hack一次,跟灰哥讨论一会才发现
//当时写的丑
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,a[N];
int main(){
n=read();
for(int i=;i<=n;i++) a[i]=read();
if(n<){
if(a[]==) printf("UP");
else if(a[]==) printf("DOWN");
else printf("-1");
return ;
} int x=a[n-],y=a[n];
if(x<y){
if(y!=) printf("UP");
else printf("DOWN");
}else{
if(y!=) printf("DOWN");
else printf("UP");
}
return ;
}
题意:最少次数使序列alternate
两种情况统计需要次数取最小
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+,INF=1e9;
int n,cntr=,cntb=,ans=INF;
char s[N]; int main(){
scanf("%d%s",&n,s+);
for(int i=;i<=n;i++){
if(i%==&&s[i]=='r')cntr++;
if(i%==&&s[i]=='b')cntb++;
}
ans=max(cntr,cntb);
cntr=cntb=;
for(int i=;i<=n;i++){
if(i%==&&s[i]=='b')cntb++;
if(i%==&&s[i]=='r')cntr++;
}
ans=min(ans,max(cntr,cntb));
printf("%d",ans);
}
Codeforces#374(Div.2)721A. One-dimensional Japanese Crossword |720B.Password
//
// main.cpp
// a
//
// Created by Candy on 9/30/16.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=1e2+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x;
}
int n,cnt=,lst[N],cur=;
char s[N];
int main(int argc, const char * argv[]) {
scanf("%d%s",&n,s+);
for(int i=;i<=n;i++){
if(s[i]=='B') {cur++;}
if(s[i]=='W') {if(cur) lst[++cnt]=cur;cur=;}
}
if(cur)lst[++cnt]=cur;
printf("%d\n",cnt);
for(int i=;i<=cnt;i++) printf("%d ",lst[i]);
return ;
}
按长度排序,看比password短的有多少,统计时间,mn就是这个时间+1
mx还要继续统计和password一样长的时间
注意如果输入password后正好达到block次数,这个不能算
PS:官方推了公式也可以 let's count two variables — cntl (the number of passwords that are shorter than Vanya's Codehorses password) and cntle (the number of passwords that are not longer than Vanya's Codehorses password). Then it's easy to see that in the best case answer will be equal to
, and in the worst case it will be
.
//
// main.cpp
// b
//
// Created by Candy on 9/30/16.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
using namespace std;
const int N=;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x;
}
int n,k,mn,mx;
vector<string> v;
vector<string>::iterator it;
string s,p;
bool cmp(string &a,string &b){
return a.size()<b.size();
}
int main(int argc, const char * argv[]) {
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
cin>>s;
v.push_back(s);
}
cin>>p;
sort(v.begin(),v.end(),cmp);
int len=p.size(),tmp=,equ=;
for(it=v.begin();it<v.end();it++){
if(it->size()<len){
tmp++;mn++;mx++;if(tmp==k){mn+=;mx+=;tmp=;}
}
if(it->size()==len){
tmp++;mx++;if(tmp==k){mx+=;tmp=;}
}
if(it->size()>len) break;
}
if(tmp==) mx-=;
printf("%d %d",mn+,mx);
return ;
}
Codeforces Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) 722A. Broken Clock |720B.Verse Pattern
A.
贪心模拟
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=;
int n;
char s[N];
int main(int argc, const char * argv[]) {
scanf("%d%s",&n,s+);
if(n==){
if(s[]>''){
if(s[]=='') s[]='';
else s[]='';
}else{
if(s[]==''&&s[]>'') s[]='';
if(s[]==''&&s[]=='') s[]='';
}
}else{
if(s[]>'') s[]='';
if(s[]==''&&s[]>'') s[]='';
}
if(s[]>'') s[]='';
printf("%s",s+);
return ;
}
B.
就是多少个元音字母
小心读入
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
const int N=;
int n,p[N];
string s,mp="aeiouy";
bool verse(char c){
for(int i=;i<mp.size();i++)
if(c==mp[i]) return ;
return ;
}
int main(int argc, const char * argv[]) {
cin>>n;int flag=;
for(int i=;i<=n;i++) cin>>p[i];
for(int i=;i<=n;i++){
getline(cin,s);while(s[]<'a'||s[]>'z') getline(cin,s);
int cnt=;
for(int j=;j<s.size();j++)
if(verse(s[j])) cnt++;
if(cnt!=p[i]) flag=;
//cout<<cnt<<"\n";
}
if(flag) cout<<"YES";
else cout<<"NO";
return ;
}
CF723A|B
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int N=3e3+,INF=1e9+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x;
}
int a[];
int main(){
for(int i=;i<=;i++) a[i]=read();
sort(a+,a+);
printf("%d",a[]-a[]);
}
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int N=;
int n,flag=,mx=,cnt=,len=;
char s[N];
int main(){
s[]='_';
scanf("%d%s",&n,s+);s[n+]='_';
for(int i=;i<=n+;i++){
if(s[i]=='_'||s[i]=='('||s[i]==')'){//printf("%d\n",i);
if((s[i-]>='a'&&s[i-]<='z')||(s[i-]>='A'&&s[i-]<='Z')){
if(!flag) mx=max(mx,len);
else cnt++;
len=;
}
}
if(s[i]=='(') flag=;
if(s[i]==')') flag=;
if((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')) len++;
}
printf("%d %d",mx,cnt);
}
CF733B.Parade
坑太多........提一点吧,三个数取最大值第一个数要同时和另两个比
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=1e5+,INF=1e9+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,w,ans,mx=-INF,mxp,mn=INF,mnp;
int main(){
n=read();
for(int i=;i<=n;i++){
w=read()-read(); ans+=w;
if(w>mx) mx=w,mxp=i;
if(w<mn) mn=w,mnp=i;
}
int t1=abs(ans-*mx),t2=abs(ans-*mn);//printf("%d %d %d %d %d\n",mx,t1,mn,t2,ans);
ans=abs(ans); if(t1>ans&&t1>t2) printf("%d",mxp);
else if(t2>ans) printf("%d",mnp);
else printf("");
}
Codeforces水题集合[14/未完待续]的更多相关文章
- Luogu题目集合[6/未完待续]
1. P1327数列排序 题目描述 给定一个数列{an},这个数列满足ai≠aj(i≠j),现在要求你把这个数列从小到大排序,每次允许你交换其中任意一对数,请问最少需要几次交换? 输入输出格式 输入格 ...
- 关于DOM的一些总结(未完待续......)
DOM 实例1:购物车实例(数量,小计和总计的变化) 这里主要是如何获取页面元素的节点: document.getElementById("...") cocument.query ...
- C++语言体系设计哲学的一些随想(未完待续)
对于静态类型语言,其本质目标在于恰当地操作数据,得到期望的值.具体而言,需要: (1)定义数据类型 你定义的数据是什么,是整形还是浮点还是字符.该类型的数据可以包含的值的范围是什么. (2)定义操作的 ...
- odoo11 model+Recordset 基础未完待续
Model 一个模型代表了一个业务对象 本质上是一个类,包含了同django flask一样的数据字段 所有定义在模型中的方法都可以被模型本身的直接调用 现在编程范式有所改变,不应该直接访问模型,而是 ...
- 我的SQL总结---未完待续
我的SQL总结---未完待续 版权声明:本文为博主原创文章,未经博主允许不得转载. 总结: 主要的SQL 语句: 数据操作(select, insert, delete, update) 访问控制(g ...
- 一篇文章让Oracle程序猿学会MySql【未完待续】
一篇文章让Oracle DB学会MySql[未完待续] 随笔前言: 本篇文章是针对已经能够熟练使用Oracle数据库的DB所写的快速学会MySql,为什么敢这么说,是因为本人认为Oracle在功能性方 ...
- 命令行操作mysql 未完待续......
复制数据表 create table 新表 like 旧表: 删除表中某个字段 alter table 表名 drop column 字段; 例子: alter table news_apply_lo ...
- 布隆过滤器(Bloom Filter) 未完待续
布隆过滤器雏形 未完待续..... 计算错误率 现在有一个空额布隆过滤器, 过滤器里的bit array的大小是m. 咱来插入一个元素. 这次插入过程中的第一个hash函数会算出一个位置, 然后把这个 ...
- Hibernate二级缓存(未完待续)
1.Hibernate的cache介绍: Hibernate实现了良好的Cache机制,可以借助Hibernate内部的Cache迅速提高系统的数据读取性能.Hibernate中的Cache可分为两层 ...
随机推荐
- JQuery插件Validation的使用-遁地龙卷风
第二版 (-1)写在前面 本文不是要详细说明Validation插件的使用,而是将满足开发需求的代码已最应该使用的方式写出来,并附有详细的注释 想要了解更多,去jquery的官网,有最新,最全面的,后 ...
- 学习zepto.js(对象方法)[1]
zepto也是使用的链式操作,链式操作:函数返回调用函数的对象. 但并不是所有的对象方法都可以进行链式操作,举几个例子:.size(),.html()|.text()//不传参数的情况下; 若非特殊说 ...
- Objective-C instancetype关键字
instancetype是clang 3.5开始,clang提供的一个关键字 表示某个方法返回的未知类型的Objective-C对象 instancetype会告诉编译器当前的类型,这点和NSObj ...
- SAP (ABAP) 常用的数学函数
Function func Return value abs Absolute value of the argument arg (绝对值) sign Plus/minus sign of the ...
- IOS开发--微信支付
前言:下面介绍微信支付的开发流程的细节,图文并茂,你可以按照我的随笔流程过一遍代码.包你也学会了微信支付.而且支付也是面试常问的内容. 正文: 1.首先在开始使用微信支付之前,有一些东西是开发者必须要 ...
- [Android]使用RecyclerView替代ListView(一)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4232560.html RecyclerView是一个比List ...
- Asp.net中GridView使用详解(引)
GridView无代码分页排序GridView选中,编辑,取消,删除GridView正反双向排序GridView和下拉菜单DropDownList结合GridView和CheckBox结合鼠标移到Gr ...
- 初学HTML 常见的标签(一) 文本标签
最近做iOS开发的过程中, 发现要涉及到JS和原生OC(Swift)的交互, 作为一个Developer, 本着克服一切问题的原则, 开始学习HTML, 在这里记录下自己的学习笔记, 方便以后的复习, ...
- HtmlHelper使用大全
许多时候我们会遇到如下场景在写一个编辑数据的页面时,我们通常会写如下代码1:<inputtype ="text" value='<%=ViewData["ti ...
- javascript和web debug技术
在前端开发中,调试技术是必不可少的技能,本文将介绍五种前端开发必备的调试技术. Weinre移动调试 DOM 断点 debugger断点 native方法hook 远程映射本地调试 Weinre 在移 ...