Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework

A. Meeting of Old Friends

 模拟
#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 ;
}
B. Filya and Homework

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[模拟]


A. Crazy Computer
非常水的模拟
#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 ;
}

B. Complete the Word 

可以枚举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[模拟]

A. Vitya in the Countryside
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
input
5
3 4 5 6 7
output
UP
input
7
12 13 14 15 14 13 12
output
DOWN
input
1
8
output
-1
Note

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 ;
}

B. Anatoly and Cockroaches

题意:最少次数使序列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 

 
扫描统计有几个B的连续快及长度,注意最后还要判断一次
//
// 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 ;
}

B.Passwords

按长度排序,看比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/未完待续]的更多相关文章

  1. Luogu题目集合[6/未完待续]

    1. P1327数列排序 题目描述 给定一个数列{an},这个数列满足ai≠aj(i≠j),现在要求你把这个数列从小到大排序,每次允许你交换其中任意一对数,请问最少需要几次交换? 输入输出格式 输入格 ...

  2. 关于DOM的一些总结(未完待续......)

    DOM 实例1:购物车实例(数量,小计和总计的变化) 这里主要是如何获取页面元素的节点: document.getElementById("...") cocument.query ...

  3. C++语言体系设计哲学的一些随想(未完待续)

    对于静态类型语言,其本质目标在于恰当地操作数据,得到期望的值.具体而言,需要: (1)定义数据类型 你定义的数据是什么,是整形还是浮点还是字符.该类型的数据可以包含的值的范围是什么. (2)定义操作的 ...

  4. odoo11 model+Recordset 基础未完待续

    Model 一个模型代表了一个业务对象 本质上是一个类,包含了同django flask一样的数据字段 所有定义在模型中的方法都可以被模型本身的直接调用 现在编程范式有所改变,不应该直接访问模型,而是 ...

  5. 我的SQL总结---未完待续

    我的SQL总结---未完待续 版权声明:本文为博主原创文章,未经博主允许不得转载. 总结: 主要的SQL 语句: 数据操作(select, insert, delete, update) 访问控制(g ...

  6. 一篇文章让Oracle程序猿学会MySql【未完待续】

    一篇文章让Oracle DB学会MySql[未完待续] 随笔前言: 本篇文章是针对已经能够熟练使用Oracle数据库的DB所写的快速学会MySql,为什么敢这么说,是因为本人认为Oracle在功能性方 ...

  7. 命令行操作mysql 未完待续......

    复制数据表 create table 新表 like 旧表: 删除表中某个字段 alter table 表名 drop column 字段; 例子: alter table news_apply_lo ...

  8. 布隆过滤器(Bloom Filter) 未完待续

    布隆过滤器雏形 未完待续..... 计算错误率 现在有一个空额布隆过滤器, 过滤器里的bit array的大小是m. 咱来插入一个元素. 这次插入过程中的第一个hash函数会算出一个位置, 然后把这个 ...

  9. Hibernate二级缓存(未完待续)

    1.Hibernate的cache介绍: Hibernate实现了良好的Cache机制,可以借助Hibernate内部的Cache迅速提高系统的数据读取性能.Hibernate中的Cache可分为两层 ...

随机推荐

  1. 马旭飞:共探H3 BPM社区发展战略

    近日,以"让天下没有难用的流程"为主题,H3 BPM10.0在北京金隅喜来登酒店正式发布. H3 BPM全新的业务流程管理系统是颠覆BPM行业的巨作,拥有众多独创技术,近200个业 ...

  2. C#的3DES加密解密算法

    C#类如下: using System; using System.Collections.Generic; using System.Text; using System.Security.Cryp ...

  3. 一步一步教你如何解锁被盗的iPhone 6S

    即使你的iPhone6S设置了六位数的密码,甚至还设置了touch ID,但我要告诉你的是:你的手机仍然能被犯罪分子解锁. 事件背景 三天前,一位苹果用户的iPhone6S被偷了.随后,小偷重置了该用 ...

  4. SharePoint回环检查(Loopback Check)相关问题

    Loopback Check(回环检查)本来不是一个SharePoint问题,是Windows Server为了增强自身安全性在Server 2003 SP1后引入的一个功能, 在近几个月中导致了一系 ...

  5. xmpp整理笔记:聊天信息的发送与显示

    任何一个信息的发送都需要关注两个部分,信息的发出,和信息在界面中的显示 往期回顾: xmpp整理笔记:环境的快速配置(附安装包)  http://www.cnblogs.com/dsxniubilit ...

  6. android studio 使用SVN 锁定文件,防止别人修改(基于Android studio 1.4 )

    首先假设开发 A , 和 开发 B , 在使用 SVN 进行项目管理.那么A如何才能 某个锁定文件,防止B修改. 1.第一步,给这个文件加锁    完成这一步,则这个文件就别锁定了. 2.第二步,假如 ...

  7. [Android L]SEAndroid开放设备文件结点权限(读或写)方法(涵盖常用操作:sys/xxx、proc/xxx、SystemProperties)

    温馨提示      建议你先了解一下上一篇博文([Android L]SEAndroid增强Androd安全性背景概要及带来的影响)所讲的内容,先对SEAndroid窥个全貌,然后再继续本节内容.   ...

  8. push notification获取device token

    第一步:申请证书: 第二步:申请app ids,应用名字必须一致.然后再进入进行编辑,使其enable,绿灯. 第三步:申请provisioning profile,生成.mobileprovisio ...

  9. XML,DTD,XSD,XSL的区别

    XML=可扩展标记语言(eXtensible Markup Language). 可扩展标记语言XML是一种简单的数据存储语言,使用一系列简单的标记描述数据,而这些标记可用 方便的方式建立,虽然XML ...

  10. Oracle与MySQL的区别

    1. Oracle是大型数据库而Mysql是中小型数据库,Oracle市场占有率达40%,Mysql只有20%左右,同时Mysql是开源的而Oracle价格非常高. 2. Oracle支持大并发,大访 ...