HPUACM第三次积分赛

A:CodeForces 520A

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.

Examples
input
Copy
12
toosmallword
output
Copy
NO
input
Copy
35
TheQuickBrownFoxJumpsOverTheLazyDog
output
Copy
YES

题意:

    如果一个字符串包含了所有的字符(a到z,不区分大小写),那么我们就说这是一个神奇的字符串。
    现在,给你一个由大写和小写字母组成的字符串,判断其是否为神奇的字符串。

思路:

        统计的时候注意一下字母的大小写就好了

扫描二维码关注公众号,回复: 1744351 查看本文章
#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

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.

Examples
input
Copy
4 6
output
Copy
2
input
Copy
10 1
output
Copy
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.


题意:
       Vasya 发现了一个奇怪的设备。在设备的前面板上,有一个红色按钮、一个蓝色按钮和一个显示了某个正整数的屏幕。在按下红色按钮之后,设备将显示的数字乘以 2。在按下蓝色按钮之后,设备将显示的数字减去 1。如果在某时刻,数字不再是正数,则设备终止运行。显示屏幕可以显示任意大的数字。初始状态下,显示屏幕显示了数字 n 。
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 

 众所周知,妙妙学姐是大土豪。一天,妙妙学姐正在研究平面坐标系,她发现她的家恰好可以放进一个坐标系里面,其中每个房间对应一个整数坐标点。

她所在的大厅坐标是(0,0),她自己的房间坐标是(a,b)。

在妙妙学姐花了五分钟完全掌握平面坐标系之后,她决定回房间休息,可是她刚刚的研究花费了巨大的体力,她已经晕头转向了。

当她随机走了s步之后,发现她恰好在自己的房间,但是她不确定自己到底是不是走了s步,她想请你帮忙判断一下,她从(0,0)走s步之后,有没有可能刚好到达她自己的房间。当然,多次经过她自己的房间是有可能的。

妙妙学姐可以确定的是,从(x,y)走一步可以到达的4个房间是(x+1,y),(x-1,y),(x,y+1),(x,y-1)。

Input

一行三个整数a,b,s,其中a,b表示妙妙学姐的房间坐标,s表示走的步数。(-10^9<=a, b <= 10^9, 1 <= s <= 2*10^9)。

Output

如果从大厅走了s步有可能到达妙妙学姐的房间,输出"Yes",否则输出"No",均不包含引号。

Sample Input
5 5 11
10 15 25
0 5 1
0 0 2
Sample Output
No
Yes
No
Yes
Hint

第4个样例一条可能的路线是: .

注意一下坐标可能是负数

#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;
}


Drazil有很多朋友,他们中有些人是快乐的,有些人是不快乐的。 Drazil想让他的朋友变得快乐。于是,他发明了以下的计划。
 
在他的朋友中,有n个男孩和m个女孩。我们把男孩从0到n-1编号,女孩从0到m-1编号。在第i天,Drazil邀请第i mod n个男孩和第i mod m个女孩一起吃饭(注意i从0开始)。如果两个人之中有一个是快乐的,那么另外一个也会变得快乐,否则,这两个人的心情状态不会改变。一个人一旦成为快乐的人(或者他原本就是快乐的),他能保持永远快乐。
 
Drazil想知道他是否可以使用该计划,使得他所有的朋友都变得快乐。
Input
 
第一行包含两个整数n和m(1≤n,m≤100)。
 
第二行包含整数b(0≤b≤n),表示Drazil的男生朋友中目前是快乐男生的数量,然后有b个不同的整数X1,X2,...,Xb(0≤Xi<n),表示这些快乐男生的编号。
 
第三行包含整数g(0≤g≤m),表示Drazil的女生朋友中目前是快乐女生的数量,然后有g个不同的整数Y1,Y2,...,Yg(0≤Yj<m),表示这些快乐女生的编号。
 
题目保证输入数据中至少有一个人不快乐。
Output
 
如果 Drazil能使得所有的朋友都变得快乐,就输出Yes,否则输出No
Sample Input
输入样例1:
2 3
0
1 0
 
输入样例2:
2 4
1 0
1 2
 
输入样例3:
2 3
1 0
1 1
Sample Output
输出样例1:
Yes
 
输出样例2:
No
 
输出样例3:
Yes

模拟一下就好了,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

uke Skywalker给了Chewbacca一个正整数x,但是Chewbacca决定把这个数改掉。他可以把整数x每个位置上的数t改成9-t。
请你帮助Chewbacca来计算一下,如何把x改成一个最小的正整数,注意,不能出现首位为0的情况。
Input

输入一个正整数x(1<=x<=10^18),表示初始的数。

Output

输出最小可以改变的数,注意不能出现首位为0的情况。

Sample Input
输入样例1:
27
 
输入样例2:
4545
Sample Output
输出样例1:
22
 
输出样例2:
4444

如果位置上的数字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) 表示矩阵的行数和列数

Output

输出一个正整数 m 表示在矩阵中的最大值

Example
Input
1
Output
1
Input
5
Output
70
Note

第二个样例中的矩阵:

{1, 1, 1, 1, 1}, 
{1, 2, 3, 4, 5}, 
{1, 3, 6, 10, 15}, 
{1, 4, 10, 20, 35}, 
{1, 5, 15, 35, 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 - 501A


Misha 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 Input

500 1000 20 30

Sample Output
Vasya

#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;
}

猜你喜欢

转载自blog.csdn.net/Hpuer_Random/article/details/80791423