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. Tabio – 轻松,高效的管理 Chrome 标签页

    Tabio 是一个 Chrome 扩展,旨在简化大量浏览器标签页的管理.它提供的搜索功能允许您快速.轻松地找到您需要的选项卡.Tabio 便于组织你的标签,简单的拖拽排序.您也可以使用输入.删除和箭头 ...

  2. Eclipse 寻找迷失的ID

    这一篇会介绍用一种蠢的办法找拓展点常量ID. 1.打开IDE,之后什么都不干,直接关闭IDE,将当前工作区间(workspace)上的文件.metadata\.plugins\org.eclipse. ...

  3. 为 MDS 修改 SharePoint 2013组件

    了解如何修改 SharePoint 项目中的组件以在 SharePoint 2013 中利用最少下载策略(MDS).   本文内容 为何修改 SharePoint 组件? 母版页 ASP.NET 页面 ...

  4. ArcGis 001270 : 合并数据失败

    描述 工具无法将服务所需的数据和资源打包. 如果用于发布 GIS 资源的路径或要向服务器复制的数据的路径大小超出了操作系统的限制,则当您向 ArcGIS 服务器复制数据时会发生此错误. 此路径包括过渡 ...

  5. Ruby学习心得之 Linux下搭建Ruby环境

    作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Ruby学习心得之 Linux下搭建Ruby环境1.前言2.Linux下安装Ruby环境 一 ...

  6. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q52-Q55)

    Question 52You are responsible for rebranding the My Sites section of a corporate SharePoint 2010 fa ...

  7. IOS开发札记

    //遍历所有的子控件,并打印其Frame +(NSString )searchAllSubviews:(UIView )superview { NSMutableString xml = [NSMut ...

  8. Servlet基础(二) Servlet的生命周期

    Servlet基础(二) Servlet的生命周期 Servlet的生命周期可以分为三个阶段: 1.初始化阶段 2.响应客户请求阶段 3.终止阶段 Servlet的初始化阶段 在下列时刻Servlet ...

  9. 安卓开发_慕课网_Fragment实现Tab(App主界面)

    学习内容来自“慕课网” 这里用Fragment来实现APP主界面 思路: 底部横向排列4个LinearLayout,每个LinearLayout包含一个图片按钮和一个文字 1.默认显示第一个功能(微信 ...

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

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