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. jquery easyui tabs单击刷新右键刷新

    单击刷新 $(".tabs-inner").click(function(){var currTab = self.parent.$('#tabs').tabs('getSelec ...

  2. 规划在sharepoint中使用安全组

    简介 如果将权限级别分配给组而非单个用户,那么管理 SharePoint 网站用户其实很简单.SharePoint 组是一组单独的用户,它还可以包含 Active Directory 组.在 Acti ...

  3. 在SSRS 里实现 SUMIF

    最近在做报表时,要实现Excel中的SUMIF的功能, 示例:SUMIF($B$2:$B$465,"East",$G$2:$G$465),即汇总B列值等于East的G列值. 在SS ...

  4. mac os intellij如何快路查看一个java类的所有方法,结构

    如果是自己写的java类,点击点击导航的project-setting-show members 如果是系统库的,点击structure 再点一下lib中的类,或者快捷键 command+F12

  5. 开放-封闭原则(OCP)开-闭原则 和 依赖倒转原则,单一职责原则

    单一职责原则 1.单一职责原则(SRP),就一个类而言,应该仅有一个引起它变化的原因 2.如果一个类承担的职责过多,就等于把这些职责耦合在一起,一个职责的变化可能会消弱或抑制这个类完成其他职责的能力. ...

  6. 统计整个Xcode工程代码行数

    打开终端,ls 查看目录,用cd命令 定位到工程所在的目录,然后调用以下命名即可把每个源代码文件行数及总数统计出来: find . "(" -name "*.m" ...

  7. iOS-公司开发者账号的申请和注册(博主原创+亲身经历+2016年申请+附带与邓白氏公司的往来邮件截图)

    不吹不黑,此篇博客真乃我的良心之作啊,希望对大家有所帮助! 链接在简书:http://www.jianshu.com/p/9de6a8eb4d88

  8. 使用开源免费类库在.net中操作Excel

    自从上次找到NPOI之后,根据园友提供的线索以及Google,又找到了一些开源免费的类库,所以都简单体验了一遍. 主要找到以下类库: MyXls(http://sourceforge.net/proj ...

  9. Android海康监控视频调用demo

    一. 开发环境 1. 操作系统:windows7(X64) 2. 开发工具:eclipse adt Build: v22.2.1-833290 JDK7 android SDK 3. 客户端设备版本: ...

  10. 遍历set集合

    1.迭代遍历:Set<String> set = new HashSet<String>();Iterator<String> iterator= set.iter ...