Codeforces Round #295 (Div. 2)

http://codeforces.com/contest/520/problem/A
A. Pangram
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.

You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.

Input

The first line contains a single integer n (1?≤?n?≤?100) — the number of characters in the string.

The second line contains the string. The string consists only of uppercase and lowercase Latin letters.

Output

Output "YES", if the string is a pangram and "NO" otherwise.

Sample test(s)
input
12
toosmallword
output
NO
input
35
TheQuickBrownFoxJumpsOverTheLazyDog
output
YES
判断是否出现过26个字母

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#include <stack>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;

using namespace std;

bool cmp(int a,int b)
{
return a>b;
}
int a[27];
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n,i,mark;
char c;
cin>>n;
cle(a);mark=0;
for(i=1;i<=n;i++)
{
cin>>c;
if(c<='z'&&c>='a')
a[c-'a']++;
else a[c-'A']++;
}
for(i=0;i<26;i++)
if(a[i]==0)
{
cout<<"NO"<<endl;mark=1;break;
}
if(!mark)
cout<<"YES"<<endl;
return 0;
}


http://codeforces.com/contest/520/problem/B
B. Two Buttons
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.

Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?

Input

The first and the only line of the input contains two distinct integers n and m (1?≤?n,?m?≤?104), separated by a space .

Output

Print a single number — the minimum number of times one needs to push the button required to get the number m out of number n.

Sample test(s)
input
4 6
output
2
input
10 1
output
9
Note

In the first example you need to push the blue button once, and then push the red button once.

In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.

可用BFS求解,注意进入队列的条件。。坑了一把

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#include <stack>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;

using namespace std;
struct node
{
int val;
ll dist;
};
bool cmp(int a,int b)
{
return a>b;
}
queue<node>q;
node v,w;
int n,m,ans;
int vis[10000]={0};
void bfs()
{
int mark=0;
node u;
u.val=n;
u.dist=0;
q.push(u);
while(!q.empty())
{
u=q.front();q.pop();
if(u.val==0)continue;
if(u.val==m){printf("%d\n",u.dist);mark=1;break;}
w.val=u.val-1,w.dist=u.dist+1;
if(w.val>0&&!vis[w.val])
{
vis[w.val]=1;
q.push(w);
}
v.val=u.val*2,v.dist=u.dist+1;
if(v.val<=10000&&!vis[v.val])
{
vis[v.val]=1;
q.push(v);
}
}
if(!mark)cout<<100000<<endl;
}
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
cin>>n>>m;
while(!q.empty())q.pop();
bfs();
return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值