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. CSS级联和继承

    2016-11-06 <CSS入门经典>第七章 1.在HTML中使用CSS样式表的三种方式: (1)内联的样式表. eg:<em style="background-whi ...

  2. [js开源组件开发]localStorage-cache本地存储的缓存管理

    localStorage-cache本地存储的缓存管理 距离上次的组件开发有近三个月的时间了,最近一直在做一些杂事,无法静下心来写写代码,也是在学习emberjs,在emberjs中有一个很重要的东西 ...

  3. javascript --- 事件冒泡与事件捕获

    事件冒泡与事件捕获 事件冒泡和事件捕获分别由微软和网景公司提出,这两个概念都是为了解决页面中事件流(事件发生顺序)的问题.考虑下面这段代码,就不写html->head,body之类的代码了,自行 ...

  4. ABAP中的数据校验-备注

    通过 function module 检查日期是否合法(DDUT_INPUT_CHECK的校验会根据账户的时间设置格式)     日期校验方式一: CALL FUNCTION ‘DATE_CHECK_ ...

  5. 计算DEM上的Profile图

    #!/usr/bin/env python # -*- coding: utf-8 -*- import sys, gdal, os from gdalconst import GA_ReadOnly ...

  6. [ javascript canvas isPointInPath(x,y) 判断点是否在最后绘制的图形中 ] javascript canvas isPointInPath(x,y) 判断点是否在最后绘制的图形中方法演示 效果之三

    <!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...

  7. [ACM] 1007 -球球方格

    与兔子方格类似,不过一秒走一格: 输入 代码 #include<iostream> using namespace std; int main(void) { int test_count ...

  8. 【转】扫盲 同步利器、分布式网盘--BT Sync

    原文地址:http://program-think.blogspot.com/2015/01/BitTorrent-Sync.html先向大伙儿宣布个好消息——经过多位热心读者的大力支持,经过几天的努 ...

  9. xmpp整理笔记:发送图片信息和声音信息

    图片和音频文件发送的基本思路就是: 先将图片转化成二进制文件,然后将二进制文件进行base64编码,编码后成字符串.在即将发送的message内添加一个子节点,节点的stringValue(节点的值) ...

  10. 关于condition variable的理解

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...