A. Fancy Fence
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
Emuskald需要用栅栏围起来,他的农场,但他太懒,构建它自己。所以他买了一个建栅栏机器人。
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.
他希望篱笆是一个正多边形。机器人沿着单一路径构建栅栏,但它只能制造围墙以同一个角度a。
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
机器人能够建造栅栏Emuskald想要什么?换句话说,有一个正多边形角是否等于a?
Input
The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a(0 < a < 180) — the angle the robot can make corners at measured in degrees.
输入的第一行包含一个整数t(0 < t < 180)——测试的数量。以下t行包含一个整数a(0 < a < 180)——机器人可以在测量角的角度。
Output
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
对于每个测试,输出一行“是”(没有引号),如果该机器人可以构建一个Emuskald希望的栅栏,如果这是不可能的,输出“不”(没有引号),。
Examples
input
3 30 60 90
output
NO YES YES
Note
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle .
在第一个测试用例,建立围栏是不可能的,因为没有正多边形角是30°。
In the second test case, the fence is a regular triangle, and in the last test case — a square.
在第二个测试用例,篱笆是一个等边三角形,和过去的测试用例,一个正方形。
思路:
在题目中我们可知的条件只有单个角的度数,和该多边形为正多边形这两个条件,但是我们可以根据正多边形的补角和恒为360°去判断该角度是否能组成一个正多边形。我们先求出输入角度的补角,再用360°去除补角,当求出来的数为正整数时,该角度能组成正多边形。公式如下:n=360/(180-a);
代码:
#include<stdio.h> #include<string.h> #include<math.h> int main(void) { int t; double n, a;//结果得取浮点数才能判断是否能整除 scanf("%d", &t); for (int i = 0; i < t; i++) {//直接循环判断输出 scanf("%lf", &a); n = 360.0 / (180.0 - a);//直接用公式判断 if ((int)n == n) {//强制转换int去判断是否为整数 printf("YES\n"); } else { printf("NO\n"); } } return 0; }
B. Kyoya and Photobooks
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?
Kyoya Ootori销售相册Ouran高中主机的俱乐部。他26张照片,标记为“a”到“z”,并且他已经将照片按照某种顺序汇编成照片小册子(可能还有一些照片重复)。照片小册子可以被描述为一个字符串的小写字母,组成的照片小册子。他现在想卖一些“特别版”的相册,每一个额外的照片在书中插入的地方。他想让尽可能多的不同的相册,所以他可以赚更多的钱。他问Haruhi,有多少不同的相册,他可以通过插入一个额外的照片到相册,他已经有了吗?
Please help Haruhi solve this problem.
请帮助Haruhi解决这个问题。
Input
The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters.
第一次输入将是单个字符串s (1 ≤ |s| ≤ 20).字符串 s 仅包含小写英文字母
Output
Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.
输出一个整数等于Kyoya Ootori可以制作的相簿的个数。
Examples
input
a
output
51
input
hi
output
76
Note
In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.
在第一个样例中,我们可以制造 'ab','ac',...,'az','ba','ca',...,'za', 和'aa', 总共可以产生51个小册子。
思路:
这个题目就是在一个长度为n(n ≤ 20)的字符串中插入一个字符串,则一共有n+1个空去插入字符串,在第一个位置里有26种情况,不用考虑重复的可能,后面的空因为要避免与前面的重复,则有25种情况。所以一共有26+25*n种情况,在代码里直接求字符串长度然后带入公式输出就好。
代码:
#include<stdio.h> #include<string.h> #include<math.h> int main(void) { char s[21]; scanf("%s", &s); int l = strlen(s); printf("%d", 26 + l * 25); return 0; }
C. Interesting drink
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in the shop i is equal to xi coins.
Vasiliy喜欢努力工作后休息,所以你可以经常见他在一些酒吧附近。跟所有程序员一样,他喜欢著名的饮料“Beecola”,可以在n个不同的商店买。众所周知,一瓶的价格在商店里i= xi硬币。
Vasiliy plans to buy his favorite drink for q consecutive days. He knows, that on the i-th day he will be able to spent mi coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
Vasiliy计划为连续q天买他最喜欢的饮料。他知道,在第i个天,他将能够花费mi硬币。现在,他想知道每一天有多少不同的商店可以买一瓶“Beecola”。
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of shops in the city that sell Vasiliy's favourite drink.
输入的第一行包含一个整数n(000年1≤n≤100)——城里的商店出售的数量Vasiliy最喜欢的饮料。
The second line contains n integers xi (1 ≤ xi ≤ 100 000) — prices of the bottles of the drink in the i-th shop.
第二行包含n个整数xi(1≤xi≤100 000)——饮料在第i个的饮料店的价格。
The third line contains a single integer q (1 ≤ q ≤ 100 000) — the number of days Vasiliy plans to buy the drink.
第三行包含一个整数q(1≤ q ≤100 000) - Vasiliy计划购买饮料的天数。
Then follow q lines each containing one integer mi (1 ≤ mi ≤ 109) — the number of coins Vasiliy can spent on the i-th day.
然后问行包含一个整数mi (1≤mi≤10^9)——硬币的数量Vasiliy可以花在第i个天。
Output
Print q integers. The i-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the i-th day.
打印q整数。第i个其中的数量应该等于商店Vasiliy能够买到一瓶喝的第i个天。
Example
input
5 3 10 8 6 11 4 1 10 3 11output
0 4 1 5Note
On the first day, Vasiliy won't be able to buy a drink in any of the shops.
第一天,Vasiliy不能买酒的商店。
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
第二天,Vasiliy可以在商店买酒1、2、3和4。
On the third day, Vasiliy can buy a drink only in the shop number 1.
第三天,Vasiliy只能在1号店买酒。
Finally, on the last day Vasiliy can buy a drink in any shop.
最后,在最后一天Vasiliy可以在任何商店买酒。
思路:
这道题就是利用对比去判断数组里有几个数是小于输入的每一个数,这道题一开始没考虑算法的时间复杂度,直接一个个去判断输出,后面几个测试案例是超时的,去看了一下别人的做法,就突然领悟,要用二分法去减少算法运行的时间,减少对比的次数。所以先将每家店的饮料价格存进数组,然后再根据每天的零花钱先去跟头一个和尾一个去对比,是否满足0个和n个的情况,然后再利用二分法去对比,得出结果。
代码:
#include<stdio.h> #include <algorithm> using namespace std; int main(void) { int n, q; int xi[100000], mi; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &xi[i]); } sort(xi + 1, xi + n + 1);//先将饮料店的价格进行排序有利于我们判断 scanf("%d", &q); for (int j = 0; j < q; j++) {//直接开始输入对比 int num = 0; scanf("%d", &mi); if (mi >= xi[n]) {//跟最大一个数进行对比 num = n; } else if (mi < xi[1]) {//跟最小一个数进行对比 num = 0; } else {//二分法 int l = 1; int x = n; int mid; while (l <= x)//一直二分判断 { mid = (l + x) / 2; if (xi[mid] <= mi)//当该分组的中间数不大于零用钱时,num与中间数的序号相等 { num = mid; l = mid + 1; } else//逐渐减小范围 x = mid - 1; } } printf("%d\n", num); } return 0; }