练习赛

1331 - Agent J
    PDF (English) Statistics Forum
Time Limit: 1 second(s) Memory Limit: 32 MB

Agent J is preparing to steal an antique diamond piece from a museum. As it is fully guarded and they are guarding it using high technologies, it's not easy to steal the piece. There are three circular laser scanners in the museum which are the main headache for Agent J. The scanners are centered in a certain position, and they keep rotating maintaining a certain radius. And they are placed such that their coverage areas touch each other as shown in the picture below:

练习赛_第1张图片

Here R1R2 and R3 are the radii of the coverage areas of the three laser scanners. The diamond is placed in the place blue shaded region as in the picture. Now your task is to find the area of this region for Agent J, as he needs to know where he should land to steal the diamond.

Input

Input starts with an integer T (≤ 1000), denoting the number of test cases.

Each case starts with a line containing three real numbers denoting R1, R2 and R3 (0 < R1, R2, R3 ≤ 100). And no number contains more than two digits after the decimal point.

Output

For each case, print the case number and the area of the place where the diamond piece is located. Error less than 10-6 will be ignored.

Sample Input

Output for Sample Input

3

1.0 1.0 1.0

2 2 2

3 3 3

Case 1: 0.16125448

Case 2: 0.645017923

Case 3: 1.4512903270

 

求出三角形面积减去各弧形面积

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define PI acos(-1.0)
using namespace std;
int main()
{
    int t,i,j,k,n,m,test=1;
    scanf("%d",&t);
    while(t--){
        double r1,r2,r3;
        scanf("%lf%lf%lf",&r1,&r2,&r3);
        double a=r1+r2,b=r1+r3,c=r2+r3;
        double p=(a+b+c)/2.0;
        double area1=(acos((a*a+b*b-c*c)/(2.0*a*b))/(2.0*PI))*(PI*r1*r1);
        double area2=(acos((b*b+c*c-a*a)/(2.0*b*c))/(2.0*PI))*(PI*r3*r3);
        double area3=(acos((a*a+c*c-b*b)/(2.0*a*c))/(2.0*PI))*(PI*r2*r2);
        printf("Case %d: %.7lf\n",test++,sqrt(p*(p-a)*(p-b)*(p-c))-area1-area2-area3);
    }
    return 0;
}

1338 - Hidden Secret!
    PDF (English) Statistics Forum
Time Limit: 1 second(s) Memory Limit: 32 MB

In this problem you are given two names, you have to find whether one name is hidden into another. The restrictions are:

1.      You can change some uppercase letters to lower case and vice versa.

2.      You can add/remove spaces freely.

3.      You can permute the letters.

And if two names match exactly, then you can say that one name is hidden into another.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with two lines. Each line contains a name consists of upper/lower case English letters and spaces. You can assume that the length of any name is between 1 and 100 (inclusive).

Output

For each case, print the case number and "Yes" if one name is hidden into another. Otherwise print "No".

Sample Input

Output for Sample Input

3

Tom Marvolo Riddle

I am Lord Voldemort

I am not Harry Potter

Hi Pretty Roar to man

Harry and Voldemort

Tom and Jerry and Harry

Case 1: Yes

Case 2: Yes

Case 3: No

 

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
char str1[110];
char str2[110];
int vis1[30];
int vis2[30];
int main()
{
    int n,i,j,k,t,test=1;
    scanf("%d",&t);
    getchar();
    while(t--){
        gets(str1);
        //getchar();
        gets(str2);
        memset(vis1,0,sizeof(vis1));
        memset(vis2,0,sizeof(vis2));
        for(i=0;i='a'&&str1[i]<='z'){
                vis1[str1[i]-'a']++;
            }
            else if(str1[i]>='A'&&str1[i]<='Z'){
                vis1[str1[i]-'A']++;
            }
        }
        for(i=0;i='a'&&str2[i]<='z'){
                vis2[str2[i]-'a']++;
            }
            else if(str2[i]>='A'&&str2[i]<='Z'){
                vis2[str2[i]-'A']++;
            }
        }
        bool sign=true;
        for(i=0;i<26;++i){
            if(vis1[i]!=vis2[i]){
                sign=false;break;
            }
        }
        printf("Case %d: ",test++);
        if(sign){
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
    }
    return 0;
}

1387 - Setu
    PDF (English) Statistics Forum
Time Limit: 2 second(s) Memory Limit: 32 MB

Rahaduzzaman Setu, (Roll - 12) of 13th batch, CSE, University of Dhaka. He passed away on 18th April 2012. This is one of the saddest news to all. May he rest in peace. This problem is dedicated to him.

This problem was written during his treatment. He will be in our prayers, always.

"He has been suffering from Multi Drug Resistant TB for a long time. Now, his left lung is damaged and beyond repair. No medicine is working on his body to ease his pain. It is urgent to operate on his left lung so that the disease doesn't spread to his right lung. It can either be removed through surgery or transplanted. He comes from a modest family and it is difficult and impossible for them to bare his medical expenses anymore. Because of the money needed (12 million BDT) to transplant, it is his family's decision to go with the surgery (3 million BDT). We must help them financially by raising money. But we must not be confined with that amount only to do the surgery. We must go for the Transplant. Our target will be to collect as much as possible to help our friend [link]."

However, in this problem, you have to build a software that can calculate the donations. Initially the total amount of money is 0 and in each time, two types of operations will be there.

1)      "donate K" (100 ≤ K ≤ 105), then you have to add K to the account.

2)      "report", report all the money currently in the account.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing an integer N (1 ≤ N ≤ 100) denoting the number of operations. Then there will be N lines each containing two types of operations as given. You may assume that the input follows the restrictions above. Initially the account is empty for each case.

Output

For each case, print the case number in a single line. Then for each "report" operation, print the total amount of money in the account in a single line.

Sample Input

Output for Sample Input

2

4

donate 1000

report

donate 500

report

2

donate 10000

report

Case 1:

1000

1500

Case 2:

10000

 

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn=1000010;
char str[10];
int main()
{
    int t,i,j,k,n,test=1;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        int ans=0;
        printf("Case %d:\n",test++);
        for(i=0;i

1414 - February 29
    PDF (English) Statistics Forum
Time Limit: 1 second(s) Memory Limit: 32 MB

It is 2012, and it's a leap year. So there is a "February 29" in this year, which is called leap day. Interesting thing is the infant who will born in this February 29, will get his/her birthday again in 2016, which is another leap year. So February 29 only exists in leap years. Does leap year comes in every 4 years? Years that are divisible by 4 are leap years, but years that are divisible by 100 are not leap years, unless they are divisible by 400 in which case they are leap years.

In this problem, you will be given two different date. You have to find the number of leap days in between them.

Input

Input starts with an integer T (≤ 550), denoting the number of test cases.

Each of the test cases will have two lines. First line represents the first date and second line represents the second date. Note that, the second date will not represent a date which arrives earlier than the first date. The dates will be in this format - "month day, year", See sample input for exact format. You are guaranteed that dates will be valid and the year will be in between 2 * 103 to 2 * 109. For your convenience, the month list and the number of days per months are given below. You can assume that all the given dates will be a valid date.

Output

For each case, print the case number and the number of leap days in between two given dates (inclusive).

Sample Input

Output for Sample Input

4

January 12, 2012

March 19, 2012

August 12, 2899

August 12, 2901

August 12, 2000

August 12, 2005

February 29, 2004

February 29, 2012

Case 1: 1

Case 2: 0

Case 3: 1

Case 4: 3

Note

The names of the months are {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" and "December"}. And the numbers of days for the months are {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 and 31} respectively in a non-leap year. In a leap year, number of days for February is 29 days; others are same as shown in previous line.


#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int leap=0;
char str[15][10]={"","January","February","March","April","May","June","July","August","September","October","November","December"};
bool judge(int y){
    return (y%4==0&&y%100!=0)||(y%400==0);
}
void init(){
    for(int i=2001;i<=2400;++i){
        leap+=judge(i);
    }
}
int main()
{
    init();
    int n,m,i,j,k,t,test=1;
    scanf("%d",&t);
    while(t--){
        char s[15];
        int y1,m1,d1,y2,m2,d2;
        scanf("%s%d,%d",s,&d1,&y1);
        for(i=1;i<=12;++i){
            if(strcmp(s,str[i])==0){
                m1=i;break;
            }
        }
        scanf("%s%d,%d",s,&d2,&y2);
        for(i=1;i<=12;++i){
            if(strcmp(s,str[i])==0){
                m2=i;break;
            }
        }
        int ans=0;
        if(y2==y1){
            if(judge(y1)){
                if((m1==1||(m1==2&&d1<=29))&&(m2>=3||(m2==2&&d2==29))){
                    printf("Case %d: %d\n",test++,1);
                }
                else {
                    printf("Case %d: %d\n",test++,0);
                }
            }
            else {
                printf("Case %d: %d\n",test++,0);
            }
            continue;
        }
        if(judge(y1)){
            if((m1==1)||(m1==2&&d1<=29))ans++;
        }
        if(judge(y2)){
            if(m2>=3||(m2==2&&d2==29))ans++;
        }
        for(i=y1+1;i<=y2-1;++i){
            ans+=judge(i);
            if(i%400==0)break;
        }
        if(i<=y2-1){
            for(j=y2-1;j>y1+1;--j){
                if(j%400==0)break;
                ans+=judge(j);
            }
            ans=ans+((j-i)/400)*leap;
        }
        printf("Case %d: %d\n",test++,ans);
    }
    return 0;
}

1433 - Minimum Arc Distance
    PDF (English) Statistics Forum
Time Limit: 2 second(s) Memory Limit: 32 MB

You all probably know how to calculate the distance between two points in two dimensional cartesian plane. But in this problem you have to find the minimum arc distance between two points and they are on a circle centered at another point.

You will be given the co-ordinates of the points A and B and co-ordinate of the center O. You just have to calculate the minimum arc distance between A and B. In the picture, you have to calculate the length of arc ACB. You can assume that A and B will always be on the circle centered at O.

练习赛_第2张图片

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing six integers Ox, Oy, Ax, Ay, Bx, By where (Ox, Oy) indicates the co-ordinate of O(Ax, Ay) denote the co-ordinate of A and (Bx, By) denote the co-ordinate of B. All the integers will lie in the range [1, 10000].

Output

For each case, print the case number and the minimum arc distance. Errors less than 10-3 will be ignored.

Sample Input

Output for Sample Input

5

5711 3044 477 2186 3257 7746

3233 31 3336 1489 1775 134

453 4480 1137 6678 2395 5716

8757 2995 4807 8660 2294 5429

4439 4272 1366 8741 6820 9145

Case 1: 6641.81699183

Case 2: 2295.92880

Case 3: 1616.690325

Case 4: 4155.64159340

Case 5: 5732.01250253

 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define PI acos(-1.0)
using namespace std;
double dist(double x1,double y1,double x2,double y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
    int t,i,j,k,n,m,test=1;
    scanf("%d",&t);
    while(t--){
        double xo,yo,xa,ya,xb,yb;
        scanf("%lf%lf%lf%lf%lf%lf",&xo,&yo,&xa,&ya,&xb,&yb);
        double r=dist(xo,yo,xa,ya);
        double c=dist(xa,ya,xb,yb);
        double ans=(acos((2.0*r*r-c*c)/(2.0*r*r))/(2.0*PI))*(2.0*r*PI);
        printf("Case %d: %.7lf\n",test++,ans);
    }
    return 0;
}

1305 - Area of a Parallelogram
    PDF (English) Statistics Forum
Time Limit: 1 second(s) Memory Limit: 32 MB

A parallelogram is a quadrilateral with two pairs of parallel sides. See the picture below:

练习赛_第3张图片

Fig: a parallelogram

Now you are given the co ordinates of A, B and C, you have to find the coordinates of D and the area of the parallelogram. The orientation of ABCD should be same as in the picture.

Input

Input starts with an integer T (≤ 1000), denoting the number of test cases.

Each case starts with a line containing six integers Ax, Ay, Bx, By, Cx, Cy where (Ax, Ay) denotes the coordinate of A(Bx, By) denotes the coordinate of B and (Cx, Cy) denotes the coordinate of C. Value of any coordinate lies in the range [-1000, 1000]. And you can assume that A, B and C will not be collinear.

Output

For each case, print the case number and three integers where the first two should be the coordinate of D and the third one should be the area of the parallelogram.

Sample Input

Output for Sample Input

3

0 0 10 0 10 10

0 0 10 0 10 -20

-12 -10 21 21 1 40

Case 1: 0 10 100

Case 2: 0 -20 200

Case 3: -32 9 1247

 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define PI acos(-1.0)
using namespace std;
struct Node{
    int x,y;
}A[5];
int main()
{
    int t,i,j,k,n,m,test=1;
    scanf("%d",&t);
    while(t--){
        scanf("%d%d%d%d%d%d",&A[0].x,&A[0].y,&A[1].x,&A[1].y,&A[2].x,&A[2].y);
        A[3].x=A[2].x+A[0].x-A[1].x;A[3].y=A[2].y+A[0].y-A[1].y;
        int ans=0;
        for(i=0;i<4;++i){
            ans=ans+(A[i].x*A[(i+1)%4].y)-(A[i].y*A[(i+1)%4].x);
        }
        if(ans%2==0){
            printf("Case %d: %d %d %d\n",test++,A[3].x,A[3].y,abs(ans)/2);
        }
        else {
            printf("Case %d: %d %d %d.5\n",test++,A[3].x,A[3].y,abs(ans)/2);
        }
    }
    return 0;
}

B. Increase and Decrease
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:

  • he chooses two elements of the array aiaj (i ≠ j);
  • he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.

The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.

Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an(|ai| ≤ 104) — the original array.

Output

Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.

Examples
input
2
2 1
output
1
input
3
1 4 1
output
3

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn=1000010;
int main()
{
	int sum=0,n,i,j,k;
	scanf("%d",&n);
	for(i=0;i

A. Buggy Sorting
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of the program gets number n and array a.

loop integer variable i from 1 to n - 1
    loop integer variable j from i to n - 1
        if (aj > aj + 1), then swap the values of elements aj and aj + 1

But Valera could have made a mistake, because he hasn't yet fully learned the sorting algorithm. If Valera made a mistake in his program, you need to give a counter-example that makes his program work improperly (that is, the example that makes the program sort the array not in the non-decreasing order). If such example for the given value of n doesn't exist, print -1.

Input

You've got a single integer n (1 ≤ n ≤ 50) — the size of the sorted array.

Output

Print n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1.

If there are several counter-examples, consisting of n numbers, you are allowed to print any of them.

Examples
input
1
output
-1
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn=1000010;
int main()
{
	int sum=0,n,i,j,k;
	scanf("%d",&n);
	if(n==1||n==2){
		printf("%d\n",-1);
	}
	else {
		for(i=n;i>=1;--i){
			printf("%d ",i);
		}
	}
	return 0;
} 

D. Colorful Graph
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You've got an undirected graph, consisting of n vertices and m edges. We will consider the graph's vertices numbered with integers from 1 to n. Each vertex of the graph has a color. The color of the i-th vertex is an integer ci.

Let's consider all vertices of the graph, that are painted some color k. Let's denote a set of such as V(k). Let's denote the value of theneighbouring color diversity for color k as the cardinality of the set Q(k) = {cu :  cu ≠ k and there is vertex v belonging to set V(k) such that nodes v and u are connected by an edge of the graph}.

Your task is to find such color k, which makes the cardinality of set Q(k) maximum. In other words, you want to find the color that has the most diverse neighbours. Please note, that you want to find such color k, that the graph has at least one vertex with such color.

Input

The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of vertices end edges of the graph, correspondingly. The second line contains a sequence of integers c1, c2, ..., cn (1 ≤ ci ≤ 105) — the colors of the graph vertices. The numbers on the line are separated by spaces.

Next m lines contain the description of the edges: the i-th line contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ nai ≠ bi) — the numbers of the vertices, connected by the i-th edge.

It is guaranteed that the given graph has no self-loops or multiple edges.

Output

Print the number of the color which has the set of neighbours with the maximum cardinality. It there are multiple optimal colors, print the color with the minimum number. Please note, that you want to find such color, that the graph has at least one vertex with such color.

Examples
input
6 6
1 1 2 3 5 8
1 2
3 2
1 4
4 3
4 5
4 6
output
3
input
5 6
4 2 5 2 4
1 2
2 3
3 1
5 3
5 4
3 4
output
2
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn=100010;
int num[maxn];
setS[maxn];
vectorG[maxn];
int main()
{
	int n,m,i,j,k;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i){
		scanf("%d",&num[i]);
	}
	int a,b;
	for(i=1;i<=m;++i){
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(i=1;i<=n;++i){
		for(j=0;j=max1){
			if(S[num[i]].size()==max1){
				if(num[i]

1241 - Pinocchio
    PDF (English) Statistics Forum
Time Limit: 0.5 second(s) Memory Limit: 32 MB

You must have heard the name of Pinocchio. If you never heard of him, don't panic, I am here to help you. But why I am introducing you to Pinocchio? Cause there is an interesting (and also quite strange) fact about him.

Pinocchio is a boy who lives in a certain village. He is a little boy, who is prone to telling lies, fabricating stories and exaggerating or creating tall tales for various reasons. But the strange fact is, when he does this, his nose gets longer. But when he tells the truth his nose gets back to normal size which is 2 cm.

Usually, when he wakes up in the morning his nose gets back to normal size. When he tells a lie, his nose grows at least 1 cm and at most 5 cm.              

Pinocchio                   Pinocchio after some lies

There is a common paradox related to him. What if he says, "My nose grows now." You may wonder why the simple looking statement leads to a paradox. The result of this deadly statement is noted below:

Assume that this sentence is true

1.      Which means that Pinocchio's nose grows now because he truthfully says it is, but then

2.      Pinocchio's nose does not grow now because it grows only as Pinocchio lies, but then

3.      Pinocchio's nose grows now because Pinocchio's nose does not grow now, and Pinocchio trustfully says it grows now, and it is false, that makes Pinocchio's sentence to be false, but then

4.      Pinocchio's nose does not grow now because Pinocchio's nose grows now, and Pinocchio trustfully says it grows now, and it is true that makes Pinocchio's sentence to be true, but then

5.      And so on ad infinitum.

 

Now assume that the sentence is false

1.      Which means that Pinocchio's nose does not grow now because he falsely says it is, but then

2.      Pinocchio's nose grows now because it grows only as Pinocchio lies, but then

3.      Pinocchio's nose does not grow now because Pinocchio's nose grows now, and Pinocchio falsely says it grows now, and it is false that makes Pinocchio's sentence to be true, but then

4.      Pinocchio's nose grows now because Pinocchio's nose does not grow now, and Pinocchio falsely says it grows now, and it is true, that makes Pinocchio's sentence to be false, but then

5.      And so on ad infinitum.

 

Now you are given some sizes of his nose in a day. Assume that he hasn't told any truth in that day and the sizes are reported in increasing order of time. You have to find the minimum number of lies he has told in that day such that the report of the sizes is true.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 10), where n denotes the total number of reports of his nose in a certain day. The next line contains n space separated integers denoting the sizes of his nose in that day. If the integers in that line is a1, a2 ... an, you can assume that

(2 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 50)

Output

For each case, print the case number and the minimum number of lies Pinocchio has told in that day. See the samples for the output format.

Sample Input

Output for Sample Input

2

5

2 3 3 3 4

4

2 3 4 5

Case 1: 2

Case 2: 3

 

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn=1000010;
int num[15];
int main()
{
    int t,i,j,k,n,test=1;
    scanf("%d",&t);
    while(t--){
        int ans=0;num[0]=2;
        scanf("%d",&n);
        for(i=1;i<=n;++i){
            scanf("%d",&num[i]);
            if((num[i]-num[i-1])%5==0){
                ans=ans+(num[i]-num[i-1])/5;
            }
            else {
                ans=ans+(num[i]-num[i-1])/5+1;
            }
        }
        printf("Case %d: %d\n",test++,ans);
    }
    return 0;
}

1249 - Chocolate Thief
    PDF (English) Statistics Forum
Time Limit: 1 second(s) Memory Limit: 32 MB

I gave some chocolates to students for their extraordinary performances. A chocolate is a cube shaped thing, which has length, width and height. All the students got the same amount of chocolates; their dimensions may be different but the volumes are same.

Now some of the students are claiming that there is one chocolate thief amongst them. So, it's not an easy task for me to find the chocolate thief, so I am asking your help.

You are given the names of the students and the dimensions of their chocolates; you have to find the name of the chocolate thief. You can assume that there can be at most one thief and if there is a thief, he took some portion of the chocolate from another student (not students).

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing an integer n (2 ≤ n ≤ 100) denoting the number of students. Each of the next n lines contains a name and three integers denoting the length, width and height of his current chocolate share. Names are strings containing alphanumeric characters and the length of a name is between 1 and 20. And length, width and height will lie in the range [1, 100]. Input follows the above restrictions.

Output

For each case, print the case number first. Then if no thief is found, print 'no thief'. Otherwise print 'x took chocolate from y' where x is the name of the chocolate thief, and y is the name of the person from whom the chocolate was taken.

Sample Input

Output for Sample Input

2

11

atq 3 4 3

mun 10 4 1

sam1 6 6 1

sam2 18 2 1

mub 1 36 1

tan 1 4 9

sha 4 3 3

di 3 12 1

nab 2 2 9

all 8 4 1

fah 3 2 6

2

ja 10 10 10

em 2 50 10

Case 1: mun took chocolate from all

Case 2: no thief

 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=1000010;
char str[110][30];
int main()
{
    int t,i,j,k,n,test=1;
    scanf("%d",&t);
    while(t--){
        int a,b,c;
        scanf("%d",&n);
        int min1=inf,max1=0,pos1,pos2;
        for(i=0;imax1){
                max1=a*b*c;
                pos1=i;
            }
            if(a*b*c

1261 - K-SAT Problem
    PDF (English) Statistics Forum
Time Limit: 2 second(s) Memory Limit: 32 MB

SAT was the first known NP-complete problem. The problem remains NP-complete even if all expressions are written in conjunctive normal form with 3 variables per clause (3-CNF), yielding the 3-SAT problem. A K-SAT problem can be described as follows:

There are n persons, and m objects. Each person makes K wishes, for each of these wishes either he wants to take an object or he wants to reject an object. You have to take a subset of the objects such that every person is happy. A person is happy if at least one of his K wishes is kept. For example, there are 3 persons, 4 objects, and K = 2, and

Person 1 says, "take object 1 or reject 2."

Person 2 says, "take object 3 or 4."

Person 3 says, "reject object 3 or 1."

So, if we take object 1 2 3, then it is not a valid solution, since person 3 becomes unhappy. But if we take 1 2 4 then everyone becomes happy. If we take only 4, it's also a valid solution. Now you are given the information about the persons' wishes and the solution we are currently thinking. You have to say whether the solution is correct or not.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing three integers nmK (1 ≤ n, m, K ≤ 30). Each of the next n lines contains K space separated integers where the ith line denotes the wishes of the ith person. Each of the integers in a line will be either positive or negative. Positive means the person wants the object in the solution; negative means the person doesn't want that in the solution. You can assume that the absolute value of each of the integers will lie between 1 and m.

The next line contains an integer p (0 ≤ p ≤ m) denoting the number of integers in the solution, followed by p space separated integers each between 1 and m, denoting the solution. That means the objects we have taken as solution set.

Output

For each case, print the case number and 'Yes' if the solution is valid or 'No' otherwise.

Sample Input

Output for Sample Input

2

3 4 2

+1 -2

+3 +4

-3 -1

1 4

1 5 3

+1 -2 +4

2 2 5

Case 1: Yes

Case 2: No

 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#define inf 0x3f3f3f3f
using namespace std;
int wish[35][35];
bool vis[35],num[35];
int main()
{
    int t,i,j,k,n,m,x,p,test=1;
    scanf("%d",&t);
    while(t--){
        scanf("%d%d%d",&n,&m,&k);
        memset(num,0,sizeof(num));
        memset(vis,0,sizeof(vis));
        memset(wish,0,sizeof(wish));
        for(i=1;i<=n;++i){
            for(j=1;j<=k;++j){
                scanf("%d",&x);
                if(wish[i][abs(x)]!=0){
                    if(wish[i][abs(x)]>0&&x<=0)wish[i][abs(x)]=2;
                    else if(wish[i][abs(x)]<0&&x>=0)wish[i][abs(x)]=2;
                }
                else {
                    wish[i][abs(x)]=x>0?1:-1;
                }
            }
        }
        scanf("%d",&p);
        for(i=1;i<=p;++i){
            scanf("%d",&x);num[x]=true;
        }
        for(i=1;i<=m;++i){
            if(num[i]){
                for(j=1;j<=n;++j){
                    if(wish[j][i]==1||wish[j][i]==2){
                        vis[j]=true;
                    }
                }
            }
            else {
                for(j=1;j<=n;++j){
                    if(wish[j][i]==-1||wish[j][i]==2){
                        vis[j]=true;
                    }
                }
            }
        }
        for(i=1;i<=n;++i){
            if(!vis[i])break;
        }
        if(i>n){
            printf("Case %d: Yes\n",test++);
        }
        else {
            printf("Case %d: No\n",test++);
        }
    }
    return 0;
}


你可能感兴趣的:(练习赛)