A:CodeForces 520A
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.
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 "YES", if the string is a pangram and "NO" otherwise.
12 toosmallword
NO
35 TheQuickBrownFoxJumpsOverTheLazyDog
YES
题意:
思路:
统计的时候注意一下字母的大小写就好了
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=1e4+6;
int main()
{
int n;
char s[105];
int z[28];
while(~scanf("%d %s",&n,s))
{
memset(z,0,sizeof(z));
for(int i=0;i<n;i++)
{
if(s[i]-'a'<0) z[s[i]-'A']++;
else z[s[i]-'a']++;
}
int ans=0;
for(int i=0;i<26;i++)
if(z[i]) ans++;
if(ans==26) printf("YES\n");
else printf("NO\n");
}
return 0;
}
B:CodeForces 520B
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?
The first and the only line of the input contains two distinct integers n and m (1 ≤ n, m ≤ 104), separated by a space .
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.
4 6
2
10 1
9
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.
Bob 想要在显示屏幕上得到数字 m 。为了获得这个结果,他最小需要按下多少次按钮?
输入
输入的第一行 (也是唯一的一行),包含了两个不同的整数 n 和 m (1 ≤ n, m ≤ 104),以空格间隔。
输出
打印仅有的一个数字 — 为了从数字 n 得到数字 m,必须最少按下多少次按钮。
示例
输入
4 6
输出
2
输入
10 1
输出
9
备注
在第一个示例中,需要按下蓝色按钮 1 次,然后按下红色按钮 1 次。
在第二个示例中,数字不必乘以 2,因此我们需要按下蓝色按钮 9 次。
思路:
我觉得由n变成m不好弄,就让m变成n,但是要注意m是奇数的时候要+1,不然m>>1会出错的
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=1e4+6;
int main()
{
int n,m;
while(~scanf("%d %d",&n,&m))
{
ll ans=0;
while(1)
{
if(m%2==1)//m是奇数的时候要加一
{
m+=1;
ans++;
}
if(m>n)//当m>n的时候 m/=2 是最优的
{
if(m/2>n)
{
m/=2;
ans++;
}
else if(m/2==n)
{
m/=2;
ans++;
break;
}
else// m/2<n
{
m/=2;
ans++;
ans+=n-m;
m=n;
break;
}
}
else
{
ans+=n-m;
m=n;
break;
}
}
printf("%lld\n",ans);
}
return 0;
}
//
C - 约会
CodeForces - 515A注意一下坐标可能是负数
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=1e4+6;
int main()
{
ll a,b,s;
while(~scanf("%lld %lld %lld",&a,&b,&s))
{
// ll n=a+b;
ll n=abs(a)+abs(b);
if(s<n) printf("No\n");
else
{
if((s-n)%2!=0) printf("No\n");
else printf("Yes\n");
}
}
return 0;
}
模拟一下就好了,i的最大值是LCM(n,m)
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=1e4+6;
int gcd(int a,int b)
{
return !b?a:gcd(b,a%b);
}
int main()
{
int n,m;
int b,x[106];
int g,y[106];
while(~scanf("%d %d",&n,&m))
{
int maxi=n*m/gcd(n,m);
// printf("GCD:%d\nLCM:%d\n",gcd(n,m),maxi);
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
scanf("%d",&b);
int z;
for(int i=0;i<b;i++)
{
scanf("%d",&z);
x[z]=1;
}
scanf("%d",&g);
for(int i=0;i<g;i++)
{
scanf("%d",&z);
y[z]=1;
}
for(int i=0;i<=maxi*2;i++)
{
if(x[i%n]||y[i%m])
{
x[i%n]=1;
y[i%m]=1;
}
}
int hb=0;
int hg=0;
for(int i=0;i<n;i++)
if(x[i])
hb++;
for(int i=0;i<m;i++)
if(y[i])
hg++;
if(hb==n&&hg==m) printf("Yes\n");
else printf("No\n");
}
return 0;
}
F - 恐怖分子
CodeForces - 514B有n个恐怖分子在站在一个平面上,每个恐怖分子都有一个位置坐标位置(x,y)。现在有一个激光武器要用来消灭这些恐怖分子,这个武器所在的位置是(x0,y0),激光武器每发射一次,就可以消灭一条直线上的所有恐怖分子。
现在,你的任务是计算最少要动用多少次激光武器,才可以消灭所有的恐怖分子。
Input第一行是3个整数N和x0,y0,分别表示恐怖分子的数量和武器所在的位置。(1<=n<=1000,-10000<=x0,y0<=1000)
接下来N行,每行两个整数表示每个恐怖分子的坐标位置Xi和Yi,恐怖分子可能站在相同的位置,但是不可能站在武器的位置上。(-10000<=Xi,Yi<=10000)
Output输出最少需要使用激光武器的次数。
Sample Input样例输入1:
4 0 0
1 1
2 2
2 0
-1 -1
样例输入2:
2 1 2
1 1
1 0
Sample Output样例输出1:
2
样例输出2:
1
Hint样例1和样例2的情况如图所示:
找 tan(sita) ,因为恐怖分子和激光武器与x轴的夹角是确定的,只需要找有多少这个夹角就好了,也就是找 y/x 有多少个,其中y,x是恐怖分子与激光武器的相对坐标,但是要注意x=0的时候,让y=abs(y)
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=1e4+6;
const double PI=acos(-1.0);
int main()
{
double a,b,x0,y0;
int n;
while(~scanf("%d %lf %lf",&n,&x0,&y0))
{
double x[maxn],y[maxn],c[maxn];
for(int i=0;i<n;i++)
{
scanf("%lf %lf",&a,&b);
x[i]=a-x0;
y[i]=b-y0;
if(x[i]==0&&y[i]<0) y[i]=-y[i];
c[i]=y[i]/x[i];
}
// for(int i=0;i<n;i++)
// printf("%lf ",c[i]);
// printf("\n");
sort(c,c+n);
// for(int i=0;i<n;i++)
// printf("%lf ",c[i]);
// printf("\n");
int ans=1;
double z=c[0];
for(int i=1;i<n;i++)
{
if(c[i]==z) continue;
else
{
z=c[i];
ans++;
}
}
printf("%d\n",ans);
}
return 0;
}
G - Chewbaсca和数字
CodeForces - 514A输入一个正整数x(1<=x<=10^18),表示初始的数。
Output输出最小可以改变的数,注意不能出现首位为0的情况。
Sample Input如果位置上的数字t>4就让t=9-t
注意一下首位是9的时候,不能改变
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=1e4+6;
int main()
{
int a[20];
char s[20];
while(~scanf("%s",s))
{
int l=strlen(s);
if(s[0]=='9') a[0]=s[0]-'0';
else if(s[0]>'4') a[0]=9-(s[0]-'0');
else a[0]=s[0]-'0';
for(int i=1;i<l;i++)
if(s[i]>'4') a[i]=9-(s[i]-'0');
else a[i]=s[i]-'0';
for(int i=0;i<l;i++)
printf("%d",a[i]);
printf("\n");
}
// cout<<"HelloWorld"<<endl;
return 0;
}
I - 表中的最大值
CodeForces - 509A一个 n × n 的矩阵 a 是这样定义的:
- 第一行和第一列包含: ai, 1 = a1, i = 1 对于所有的 i = 1, 2, ..., n.
- 表中剩余的每个数字等于它上面的数字和它的左边的数字的总和。换句话说,其余元素由后面辣个公式定义 ai, j = ai - 1, j + ai, j - 1.
这些条件定义表中的所有值。
给你一个数 n. 你需要求出给定的 n × n 的矩阵中最大的数
Input只有一行给一个正整数 n (1 ≤ n ≤ 10) 表示矩阵的行数和列数
输出一个正整数 m 表示在矩阵中的最大值
1
1
5
70
第二个样例中的矩阵:
矩阵是不变的,打个表就行了,公式题目都给说出来了
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=1e4+6;
int main()
{
ll a[12][12];
int n;
for(int i=1;i<12;i++)
{
a[i][1]=1;
a[1][i]=1;
}
for(int i=2;i<12;i++)
for(int j=2;j<12;j++)
a[i][j]=a[i-1][j]+a[i][j-1];
while(~scanf("%d",&n))
printf("%lld\n",a[n][n]);
// cout<<"HelloWorld"<<endl;
return 0;
}
J - 新年运输
CodeForces - 500A“直线世界”的新年正在到来!在这个世界中,有 n 个单元格,被编号为从 1 到 n 的整数,成为一个 1 × n 的棋盘。人们生活在单元格中。然而,难以在不同单元格之间移动,因为逃离单元格具有难度。人们想与生活在其它单元格中的其他人相遇。
因此,用户 tncks0121 制作了一套在这些单元格之间移动的运输系统,来庆祝新年。首先,他考虑了 n - 1 个正整数 a1, a2, ..., an - 1 。对于每个整数 i (其中 1 ≤ i ≤ n - 1),满足条件 1 ≤ ai ≤ n - i 。其次,他制作了 n - 1 个传送门,使用从 1 到 n - 1 的整数编号。第 i(1 ≤ i ≤ n - 1) 个传送门连接了单元格 i 和单元格 (i + ai),并且一个人可以使用第 i 个传送门,从单元格 i 出发,旅行到单元格 (i + ai) 。不幸的是,一个人不能反向使用传送门,这意味着不能使用第 i 个传送门,从单元格 (i + ai) 移向单元格 i 。这是显而易见的,因为存在条件 1 ≤ ai ≤ n - i ,一个人不允许使用传送门离开“直线世界”。
当前,我站在单元格 1 处,并且我想前往单元格 t 。然而,我不知道是否可能抵达那里。请判断,通过使用已建造的运输系统,我是否能够前往单元格 t 。
输入第一行包含了两个以空格分隔的整数 n (3 ≤ n ≤ 3 × 104) 和 t (2 ≤ t ≤ n) — 表示单元格的数目,以及我想要前往的目标单元格的索引。
第二行包含 n - 1 个以空格分隔的整数 a1, a2, ..., an - 1 (1 ≤ ai ≤ n - i)。数据保证:使用给定的运输系统,一个人无法离开“直线世界”。
如果我能够使用此运输系统前往单元格 t ,则打印 "YES"。否则,打印 "NO"。
8 4 1 2 1 2 1 2 1
YES
8 5 1 2 1 2 1 1 1
NO
在第一个示例中,已访问的单元格是:1, 2, 4;因此,我们能够成功访问单元格 4。
在第二个示例中,可能访问的单元格是:1, 2, 4, 6, 7, 8;因此,我们无法访问想要前往的单元格 5。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=3*1e4+6;
int a[maxn];
int main()
{
int n,t;
while(~scanf("%d %d",&n,&t))
{
memset(a,0,sizeof(a));
for(int i=1;i<n;i++)
scanf("%d",a+i);
int pos=1;
int i=1;
while(1)
{
if(pos>t)
{
printf("NO\n");
break;
}
if(pos==t)
{
printf("YES\n");
break;
}
pos+=a[i];
i=pos;
// printf("%d ",pos);
}
}
return 0;
}
K - 比赛
CodeForces - 501AMisha and Vasya参加了CF的比赛, 很不幸的是由于他们太菜,每个人都只解出一个题目。但他们代码写的都很仔细,都在第一次提交的时候通过了。现在已知Misha解出的题目价值a分而Vasya解出的题目价值为b分。此外,Misha花了c分钟才解出题目,Vasya花d分钟解出了题目。
然而CF作为高(diao)端(si)程序猿才能玩的比赛,可不是你解出多少分的题就能得到多少分,你得到的分数会随着你所用的时间的增加而减少。举个栗子,如果你花t分钟解出一道分值为p的题目,你能得到的分数为分。
现在你需要告诉Misha和Vasya这两个菜鸡他俩谁在这次比赛中得分更高~
Input输入为四个数,分别为a,b,c,d(250 ≤ a, b ≤ 3500, 0 ≤ c, d ≤ 180).
保证a和b都是250的倍数
Output输出一行:
如果Misha得分高于Vasya,输出"Misha"(不带双引号);
如果Misha得分低于Vasya,输出"Vasya" (不带双引号);
如果两人得分相同,输出"Tie" (不带双引号)。
Sample Input500 1000 20 30
Sample OutputVasya
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=1e4+6;
int main()
{
double p1,p2,t1,t2;
while(~scanf("%lf %lf %lf %lf",&p1,&p2,&t1,&t2))
{
double ans1=max(3*p1/10.0,p1-p1/250.0*t1);
double ans2=max(3*p2/10.0,p2-p2/250.0*t2);
if(ans1>ans2) printf("Misha\n");
else if(ans1<ans2) printf("Vasya\n");
else printf("Tie\n");
}
return 0;
}