OUC_TeamTraining_#1 720

D - The Mirror of Galadriel
Time Limit:2000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

With water from the stream Galadriel filled the basin to the brim, and breathed on it, and when the water was still again she spoke. 'Here is the Mirror of Galadriel,' she said. 'I have brought you here so that you may look in it, if you will. For this is what your folk would call magic, I believe; though I do not understand clearly what they mean; and they seem also to use the same word of the deceits of the Enemy. But this, if you will, is the magic of Galadriel. Did you not say that you wished to see Elf-magic?' - Galadriel to Frodo and Sam, describing her Mirror.
We call a string S magical if every substring of S appears in Galadriel's Mirror (under lateral inversion). In other words, a magical string is a string where every substring has its reverse in the string.
Given a string S, determine if it is magical or not.
Input (STDIN):
The first line contains T, the number of test cases. The next T lines contain a string each. 
Output (STDOUT):
For each test case, output "YES" if the string is magical, and "NO" otherwise.
Constraints:
1 <= T <= 100
1 <= |S| <= 10
S contains only lower-case characters.
Time Limit: 1s
Memory Limit: 64MB
Sample Input:
2
aba
ab
Sample Output:
YES
NO
Notes/Explanation of Sample Input:
For the first test case, the list of substrings are : a, b, ab, ba, aba. The reverse of each of these strings is present as a substring of S too.
For the second test case, the list of substring are : a, b, ab. The reverse of "ab", which is "ba" is not present as a substring of the string.

With water from the stream Galadriel filled the basin to the brim, and breathed on it, and when the water was still again she spoke. 'Here is the Mirror of Galadriel,' she said. 'I have brought you here so that you may look in it, if you will. For this is what your folk would call magic, I believe; though I do not understand clearly what they mean; and they seem also to use the same word of the deceits of the Enemy. But this, if you will, is the magic of Galadriel. Did you not say that you wished to see Elf-magic?' - Galadriel to Frodo and Sam, describing her Mirror.

We call a string S magical if every substring of S appears in Galadriel's Mirror (under lateral inversion). In other words, a magical string is a string where every substring has its reverse in the string.

Given a string S, determine if it is magical or not.

Input (STDIN):

The first line contains T, the number of test cases. The next T lines contain a string each. 

Output (STDOUT):

For each test case, output "YES" if the string is magical, and "NO" otherwise.

Constraints:

1 <= T <= 100

1 <= |S| <= 10

S contains only lower-case characters.

Sample Input:

2

aba

ab

Sample Output:

YES

NO

Notes/Explanation of Sample Input:

For the first test case, the list of substrings are : a, b, ab, ba, aba. The reverse of each of these strings is present as a substring of S too.

For the second test case, the list of substring are : a, b, ab. The reverse of "ab", which is "ba" is not present as a substring of the string.

 一个字符串的所有子串倒序后还是该字符串的子串。(规律就是这个字符串是对称的。)

 1 #include<stdio.h>
 2 #include<string.h>
 3 char str[150];
 4 char str2[150];
 5 int main()
 6 {
 7     int t;
 8     int len;
 9     scanf("%d",&t);
10     while(t--)
11     {
12         scanf("%s",str);
13         len = strlen(str);
14         int i = 0,j = len-1;
15         for(;i < len;i++,j--)
16         {
17             str2[j] = str[i];
18         }
19         if(strcmp(str,str2) == 0)
20             printf("YES
");
21         else
22             printf("NO
");
23         memset(str,'',150);
24         memset(str2,'',150);
25         len = 0;
26     }
27     return 0;
28 }
View Code
G - The Glittering Caves of Aglarond
Time Limit:2000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

'Strange are the ways of Men, Legolas! Here they have one of the marvels of the Northern World, and what do they say of it? Caves, they say! Caves! Holes to fly to in time of war, to store fodder in! My good Legolas, do you know that the caverns of Helm's Deep are vast and beautiful? There would be an endless pilgrimage of Dwarves, merely to gaze at them, if such things were known to be. Aye indeed, they would pay pure gold for a brief glance!

'And, Legolas, when the torches are kindled and men walk on the sandy floors under the echoing domes, ah! then, Legolas, gems and crystals and veins of precious ore glint in the polished walls; and the light glows through folded marbles, shell-like, translucent as the living hands of Queen Galadriel.' - Gimli, describing to Legolas the Glittering Caves of Aglarond.

While these caves are by and large natural, there is one place where the Men of Rohan have chiseled into the rock to create a magnificent exhibit. You have a wall of the cave consisting of 'lighted diamonds' arranged in a N by M grid (basically, you have a light behind each diamond which can be turned on or off). Further, you have a switch corresponding to each row of this diamond-grid. When you operate a switch, it will toggle (flip) the lights corresponding to that row.

You are given the current configuration of the lighted diamonds. Gimli challenges Legolas to turn on as many diamonds as possible using EXACTLY K on/off operations of the switches. Since Legolas is an Elf of the Wood and doesn't care much for things that glitter, he instead asks for your help. Note that the same switch (i.e. row) can be chosen multiple times.

Input (STDIN):

The first line contains the number of test cases T. Each test case contains N, M and K on the first line followed by N lines containing M characters each. The ith line denotes the state of the diamonds in the ith row, where '*' denotes a diamond which is on and '.' denotes a diamond which is off.

Output (STDOUT):

Output T lines containing the answer for the corresponding case.

Between successive test cases, there should not be any blank lines in the output.

Constraints:

1 <= T <= 100

1 <= N,M <= 50

1 <= K <= 100

Sample Input:

2

2 2 1

..

**

2 2 2

..

**

Sample Output:

4

2

Notes/Explanation of Sample Input:

In the first test case, row 1 can be toggled hence leaving all 4 lights to be in the ON state.

In the second test case, row 1 (or row 2) can be toggled twice, hence maintaining the state of the initial configuration. 

 题意是 有N行M列个钻石,每一个钻石后面都有一个灯,初始状态不一定。有开关进行操作,但是一次操作就是一行钻石,(开就变成关,关就变成开),必须有K次操作,输出进行完操作后,亮着的钻石个数的最大值。
方法:记录每一行亮灯的个数,每次只操作亮灯最少的那一行。
 1 #include<stdio.h>
 2 #include<string.h>
 3 char D[51][51];    
 4 int l[51] = {0};
 5 int Min(int l[51],int n)
 6 {
 7     int i,min = l[0],j = 0;
 8     for(i = 0;i < n;i++)
 9     {
10         if(min > l[i])
11         {
12             min = l[i];
13             j = i;
14         }
15     }
16     return j;
17 }
18 int main()
19 {
20     int T,M,N,K,min = 0;
21     scanf("%d",&T);
22     while(T--)
23     {
24         scanf("%d%d%d",&N,&M,&K);
25         getchar();
26         int i,j;
27     
28         for(i = 0;i < N;i++)
29         {
30             for(j = 0;j <M;j++)
31             {
32                 scanf("%c",&D[i][j]);
33                 if(D[i][j] == '*')l[i]++;
34             }
35             getchar();
36         }
37         
38         while(K--)
39         {
40             min = Min(l,N);
41             l[min] = M - l[min];
42         }
43         int sum = 0;
44         for(i = 0;i < N;i++)
45         {
46             sum += l[i];
47         }
48         printf("%d
",sum);
49         memset(l,0,sizeof(l));
50     }
51     return 0;
52 }
View Code

下面这道题一直交不对不知道是不是理解题错了。

G - The Glittering Caves of Aglarond

Time Limit:2000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit     Status       Practice        SPOJ AMR12G

Description

' Strange are the ways of Men, Legolas! Here they have one of the marvels of the Northern World, and what do they say of i? Caves, they say! Caves! Holes to fly to in time of war, to store fodder in! My good Legolas, do you know that the caverns of Helm's Deep are vast and beautiful? There would be an endless pilgrimage of Dwarves, merely to gaze at them, if such things were known to be. Aye indeed, they would pay pure gold for a brief glance!'And, Legolas, when the torches are kindled and men walk on the sandy floors under the echoing domes, ah! then, Legolas, gems and crystals and veins of precious ore glint in the polished walls; and the light glows through folded marbles, shell-like, translucent as the living hands of Queen Galadriel.' - Gimli, describing to Legolas the Glittering Caves of Aglarond.While these caves are by and large natural, there is one place where the Men of Rohan have chiseled into the rock to create a magnificent exhibit. You have a wall of the cave consisting of 'lighted diamonds' arranged in a N by M grid (basically, you have a light behind each diamond which can be turned on or off). Further, you have a switch corresponding to each row of this diamond-grid. When you operate a switch, it will toggle (flip) the lights corresponding to that row.You are given the current configuration of the lighted diamonds. Gimli challenges Legolas to turn on as many diamonds as possible using EXACTLY K on/off operations of the switches. Since Legolas is an Elf of the Wood and doesn't care much for things that glitter, he instead asks for your help. Note that the same switch (i.e. row) can be chosen multiple times.Input (STDIN):The first line contains the number of test cases T. Each test case contains N, M and K on the first line followed by N lines containing M characters each. The ith line denotes the state of the diamonds in the ith row, where '*' denotes a diamond which is on and '.' denotes a diamond which is off.Output (STDOUT):Output T lines containing the answer for the corresponding case.Between successive test cases, there should not be any blank lines in the output.Constraints:1 <= T <= 1001 <= N,M <= 501 <= K <= 100Sample Input:22 2 1..**2 2 2..**Sample Output:42Notes/Explanation of Sample Input:In the first test case, row 1 can be toggled hence leaving all 4 lights to be in the ON state.In the second test case, row 1 (or row 2) can be toggled twice, hence maintaining the state of the initial configuration. 

Strange are the ways of Men, Legolas! Here they have one of the marvels of the Northern World, and what do they say of it? Caves, they say! Caves! Holes to fly to in time of war, to store fodder in! My good Legolas, do you know that the caverns of Helm's Deep are vast and beautiful? There would be an endless pilgrimage of Dwarves, merely to gaze at them, if such things were known to be. Aye indeed, they would pay pure gold for a brief glance!

 

'And, Legolas, when the torches are kindled and men walk on the sandy floors under the echoing domes, ah! then, Legolas, gems and crystals and veins of precious ore glint in the polished walls; and the light glows through folded marbles, shell-like, translucent as the living hands of Queen Galadriel.' - Gimli, describing to Legolas the Glittering Caves of Aglarond.

While these caves are by and large natural, there is one place where the Men of Rohan have chiseled into the rock to create a magnificent exhibit. You have a wall of the cave consisting of 'lighted diamonds' arranged in a N by M grid (basically, you have a light behind each diamond which can be turned on or off). Further, you have a switch corresponding to each row of this diamond-grid. When you operate a switch, it will toggle (flip) the lights corresponding to that row.

You are given the current configuration of the lighted diamonds. Gimli challenges Legolas to turn on as many diamonds as possible using EXACTLY K on/off operations of the switches. Since Legolas is an Elf of the Wood and doesn't care much for things that glitter, he instead asks for your help. Note that the same switch (i.e. row) can be chosen multiple times.

Input (STDIN):

The first line contains the number of test cases T. Each test case contains N, M and K on the first line followed by N lines containing M characters each. The ith line denotes the state of the diamonds in the ith row, where '*' denotes a diamond which is on and '.' denotes a diamond which is off.

Output (STDOUT):

Output T lines containing the answer for the corresponding case.

Between successive test cases, there should not be any blank lines in the output.

Constraints:

1 <= T <= 100

1 <= N,M <= 50

1 <= K <= 100

Sample Input:

2

2 2 1

..

**

2 2 2

..

**

Sample Output:

4

2

Notes/Explanation of Sample Input:

In the first test case, row 1 can be toggled hence leaving all 4 lights to be in the ON state.

In the second test case, row 1 (or row 2) can be toggled twice, hence maintaining the state of the initial configuration. 

题目的意思应该是有一队士兵要被涂上颜色,每次必须涂K个士兵,传送带可以向前走可以向后走。给出规定的颜色,如果能被涂出颜色 输出最少要涂色的次数 如果不能 输出-1

我是这样想的,要是能被涂好颜色必须 前K个或后K个是一样的颜色,否则不行。如果前K个不一样后K个一样传送带从前向后走,如果前K个一样后K个不一样 传送带从后向前走,如果两边都能走,则从前向后,从后向前结果应该是一样的。这里还有一个问题是,不会存在传送带一会向前一会向后的情况,那样就没有意义了。所以在一开始就要确定方向就好了。然后传送带在走的过程中每次处理K个士兵,先都涂上K个中第一个的颜色,不符合要求的留下来再涂。写成代码就是如果前后不一样就要加1如果一样集齐K个后就要加1.

但是交了就是不对 好懊恼 要是有路过的大神求指点~~

 

 1 #include<stdio.h>
 2 #include<string.h>
 3 char D[51][51];    
 4 int l[51] = {0};
 5 int Min(int l[51],int n)
 6 {
 7     int i,min = l[0],j = 0;
 8     for(i = 0;i < n;i++)
 9     {
10         if(min > l[i])
11         {
12             min = l[i];
13             j = i;
14         }
15     }
16     return j;
17 }
18 int main()
19 {
20     int T,M,N,K,min = 0;
21     scanf("%d",&T);
22     while(T--)
23     {
24         scanf("%d%d%d",&N,&M,&K);
25         getchar();
26         int i,j;
27     
28         for(i = 0;i < N;i++)
29         {
30             for(j = 0;j <M;j++)
31             {
32                 scanf("%c",&D[i][j]);
33                 if(D[i][j] == '*')l[i]++;
34             }
35             getchar();
36         }
37         
38         while(K--)
39         {
40             min = Min(l,N);
41             l[min] = M - l[min];
42         }
43         int sum = 0;
44         for(i = 0;i < N;i++)
45         {
46             sum += l[i];
47         }
48         printf("%d
",sum);
49         memset(l,0,sizeof(l));
50     }
51     return 0;
52 }
View Code

编译器太难用了颜色什么的忽略吧 凑活看吧

 

 

原文地址:https://www.cnblogs.com/lwy-kitty/p/3203299.html