OUC_TeamTraining_#1 720
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\n",sum); 49 memset(l,0,sizeof(l)); 50 } 51 return 0; 52 }
下面这道题一直交不对不知道是不是理解题错了。
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\n",sum); 49 memset(l,0,sizeof(l)); 50 } 51 return 0; 52 }
编译器太难用了颜色什么的忽略吧 凑活看吧