Description
Input
Output
Sample Input
1 # include<cstdio> 2 # include<iostream> 3 4 using namespace std; 5 6 7 int gcd ( int a,int b ) 8 { 9 if ( b==0 ) 10 return a; 11 return gcd(b,a%b); 12 } 13 14 15 int main(void) 16 { 17 int t;scanf("%d",&t); 18 while ( t-- ) 19 { 20 long long ans = 0; 21 long long n;scanf("%lld",&n); 22 23 24 if ( n%2 ) 25 ans = (n/2)*(n-n/2); 26 else 27 { 28 for ( long long i = n/2;i>=1;i-- ) 29 { 30 if ( gcd(i,n-i)==1 ) 31 { 32 ans = i*(n-i); 33 break; 34 } 35 } 36 } 37 printf("%lld\n",ans); 38 39 } 40 41 42 return 0; 43 }
Description
Vasya lives in a strange world. The year has n months and the i-th month has ai days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to d. It is guaranteed that ai ≤ d for all i from 1 to n. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number d + 1, so after day number d it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day d is also followed by day 1.
Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month.
A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the n-th month inclusive, considering that on the first day of the first month the clock display showed day 1.
Input
The first line contains the single number d — the maximum number of the day that Vasya's clock can show (1 ≤ d ≤ 106).
The second line contains a single integer n — the number of months in the year (1 ≤ n ≤ 2000).
The third line contains n space-separated integers: ai(1 ≤ ai ≤ d) — the number of days in each month in the order in which they follow, starting from the first one.
Output
Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.
Sample Input
4
2
2 2
2
5
3
3 4 3
3
31
12
31 28 31 30 31 30 31 31 30 31 30 31
7
Hint
In the first sample the situation is like this:
1 # include<cstdio> 2 # include<iostream> 3 4 using namespace std; 5 6 # define MAX 2333 7 8 int a[MAX]; 9 10 int main(void) 11 { 12 int ans = 0; 13 int n,d;scanf("%d%d",&d,&n); 14 for ( int i = 0;i < n;i++ ) 15 scanf("%d",&a[i]); 16 for ( int i = 0;i < n-1;i++ ) 17 ans+=(d-a[i]); 18 19 printf("%d\n",ans); 20 21 return 0; 22 }
Description
You have two positive integers w and h. Your task is to count the number of rhombi which have the following properties:
Count the number of such rhombi.
Let us remind you that a rhombus is a quadrilateral whose four sides all have the same length.
Input
The first line contains two integers w and h(1 ≤ w, h ≤ 4000) — the rectangle's sizes.
Output
Print a single number — the number of sought rhombi.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Sample Input
2 2
1
1 2
0
Hint
In the first example there exists only one such rhombus. Its vertices are located at points (1, 0), (2, 1), (1, 2), (0, 1).
题目大意:
就是说在一个w*h的网格中,找出由几个点能够组成对角线平行于x轴和y轴而且四条边相等的菱形。
解题思路:
直接枚举菱形的中点个数就OK了,慢慢画下,5个图一般就出规律了。。。
代码:
1 # include<cstdio> 2 # include<iostream> 3 4 using namespace std; 5 6 7 int main(void) 8 { 9 int w,h;scanf("%d%d",&w,&h); 10 long long sum = 0; 11 for ( int i = 1;i <= w;i++ ) 12 { 13 for ( int j = 1;j <= h;j++ ) 14 { 15 sum+=min(i,w-i)*min(j,h-j); 16 } 17 } 18 19 printf("%lld\n",sum); 20 21 return 0; 22 }
Description
Input
Output
Sample Input
Sample Output
题目大意:
这题目有点意思,就是说,我现在有一个字符串,然后让你求出有多有个hehe,每个hehe可以被替换成为wqnmlgb,找规律的题目,直接上来打表然后运用乘法原理就好了。
解题思路:
fac[i] = fac[i-1]+fac[i-2], 然后 ans = ( ans*fac[cnt])%MOD;
代码:
1 # include<cstdio> 2 # include<iostream> 3 # include<cstring> 4 5 using namespace std; 6 7 # define MAX 2333 8 # define MOD 10007 9 10 char s[MAX]; 11 int fac[10088]; 12 13 14 void init() 15 { 16 fac[0] = 1; 17 fac[1] = 1; 18 fac[2] = 2; 19 for ( int i = 3;i <= 10086;i++ ) 20 { 21 fac[i] = (fac[i-1]+fac[i-2])%MOD; 22 } 23 } 24 25 int main(void) 26 { 27 init(); 28 int icase = 1; 29 int t;scanf("%d",&t); 30 while ( t-- ) 31 { 32 int cnt = 0, ans = 1; 33 scanf("%s",s); 34 int len = strlen(s); 35 for ( int i = 0;i < len; ) 36 { 37 if ( s[i]=='h'&&s[i+1]=='e' ) 38 { 39 cnt++; 40 i+=2; 41 } 42 else 43 { 44 ans = (ans*fac[cnt])%MOD; 45 cnt = 0; 46 i++; 47 } 48 49 } 50 ans = (ans*fac[cnt])%MOD; 51 52 printf("Case %d: %d\n",icase++,ans); 53 } 54 55 56 return 0; 57 }
题目大意:
就是说, 有两个人,一个叫Alice,一个叫Bob,然后这两个人玩一个游戏,把一个n*m的只包含有0和1的棋盘上的棋子进行翻转。如果Alice将所有的棋子都被翻成了0的话,那么Alice就胜利了,反之,就是Bob胜利了。
解题思路:
看到后,感觉是什么nim游戏还是什么sg定理,,,(真是扯淡)这不就是最简单的博弈吗?就是说,只要最后一个棋子是0的话,那就绝壁是Alice胜利,如果最后一个棋子是1的话,那就绝壁是Bob胜利了。因为,想想啊, 如果最后一个棋子是1的话,那Alice不管怎么翻棋子,都会使最后一个棋子变成0,这样的话,Bob就输了,如果最后一个棋子是0的话,那么Alice的每次操作都会使他变成1,那么Bob就能胜利了,因为Bob可以把他变成0。
代码:
# include<cstdio> # include<iostream> using namespace std; int n,m; int main(void) { int t;scanf("%d",&t); while( t-- ) { scanf("%d%d",&n,&m); int x; for( int i = 0;i < n;i++ ) for( int j = 0;j < m;j++ ) scanf("%d",&x); if( x == 1 ) printf("Alice\n"); else printf("Bob\n"); } return 0; }
Description
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring t of the string s.
Prefix supposed that the substring t is the beginning of the string s; Suffix supposed that the substring t should be the end of the string s; and Obelix supposed that t should be located somewhere inside the string s, that is, t is neither its beginning, nor its end.
Asterix chose the substring t so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring t aloud, the temple doors opened.
You know the string s. Find the substring t or determine that such substring does not exist and all that's been written above is just a nice legend.
Input
You are given the string s whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Output
Print the string t. If a suitable t string does not exist, then print "Just a legend" without the quotes.
Sample Input
fixprefixsuffix
fix
abcdabc
Just a legend
题目大意:
就是说,给你一个字符串,让你找到一个子串,即是这个字符串的前缀,也是这个字符串的后缀,但是还在中间出现过,就是说,既不是前也不是后缀。
解题思路:
看上去很吓人,但是仔细一想还是很简单的,就是说,kmp中的next[]数组的巧妙运用了,如果next[]玩的好,这题就很水了,如果不会next[]数组,这题
只能放了。我们知道next[i] = j 表示的是s(0,1,2,3,,,i-1)这个字符串的前缀后缀最大值,OK,有了这个概念的话,我们就把所有可能出现的长度记录下,然后我们
贪心的从最后一位还是扫,如果book[next[i]]标记过,而且next[i]的数值不是0的话,我们就输出好了,如果next[i]的数值是0的话,我们就直接跳到i=next[i]的位置了。
代码:
1 # include<cstdio> 2 # include<iostream> 3 # include<cstring> 4 5 using namespace std; 6 7 # define MAX 1000004 8 9 char s1[MAX],s2[MAX]; 10 int book[MAX]; 11 int next[MAX]; 12 13 14 void get_next ( int *next,char *s2,int lens ) 15 { 16 int t1 = 0, t2; 17 next[0] = t2 = -1; 18 while ( t1 < lens ) 19 { 20 if ( t2==-1||s2[t2]==s2[t1] ) 21 { 22 t1++, t2++; 23 next[t1] = t2; 24 } 25 else 26 t2 = next[t2]; 27 } 28 } 29 30 31 int kmp ( int *next,char *s1,int lens1,char *s2,int lens2 ) 32 { 33 int t1 = 0,t2 = 0; 34 while ( t1 < lens1&&t2 < lens2 ) 35 { 36 if ( t2==-1||s1[t1]==s2[t2] ) 37 { 38 t1++; t2++; 39 } 40 else 41 t2 = next[t2]; 42 } 43 if ( t2==lens2 ) 44 return 1; 45 else 46 return 0; 47 } 48 49 50 int main(void) 51 { 52 while ( scanf("%s",s2)!=EOF ) 53 { 54 int lens1 = strlen(s1), lens2 = strlen(s2); 55 get_next( next,s2,lens2 ); 56 // int flag = kmp ( next,s1,lens1,s2,lens2 ); 57 for ( int i = 0;i < lens2;i++ ) 58 book[next[i]] = 1; 59 int flag = 0, j = 0; 60 61 for ( int i = lens2;next[i];i = next[i] ) 62 { 63 if ( book[next[i]]==1 ) 64 { 65 for ( j = 0;j < next[i];j++ ) 66 { 67 printf("%c",s2[j]); 68 } 69 flag = 1; 70 break; 71 } 72 } 73 74 if ( flag ) 75 printf("\n"); 76 else 77 printf("Just a legend\n"); 78 memset(s2,0,sizeof(s2)); 79 memset(book,0,sizeof(book)); 80 } 81 82 return 0; 83 }