周赛题

LightOJ - 1331
Time Limit:                                                        1000MS                      Memory Limit: 32768KB64bit IO Format:                            %lld & %llu                      

SubmitStatus

Description

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 areastouch each other as shown in the picture below:

Here R1, R2 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 than10-6 will be ignored.

Sample Input

3

1.0 1.0 1.0

2 2 2

3 3 3

Sample Output

Case 1: 0.16125448

Case 2: 0.645017923

Case 3: 1.4512903270

Hint

Source

Problem Setter: Jane Alam Jan
//题意:
给你三个圆的半径,这三个圆是两两相切的,让你求出这三个圆之间所夹的面积。
//思路:
先分析怎样得到那个阴影面积,将三个圆心连接后,形成一个三角形,扇形面积就等于三角形面积减去三个扇形面积。
怎样求三个扇形的面积呢?先用余弦定理求出每个角的cos值(因为三条边的长度已知),再根据cos值求出三个角的大小,再根据求扇形面积公式求出3个扇形面积,再用三角形面积减去3个扇形面积即可。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#define PI acos(-1.0)
using namespace std;
int main()
{
	int t,T=1;
	double r1,r2,r3;
	scanf("%d",&t);
	while(t--)
	{
		double tmp,a,b,c,A,B,C,SA,CA,CB,CC;
		double S,s1,s2,s3,s;
		scanf("%lf%lf%lf",&r1,&r2,&r3);
		a=r1+r2;b=r1+r3;c=r2+r3;
		CA=(b*b+c*c-a*a)/(2*b*c);
		CB=(a*a+c*c-b*b)/(2*a*c);
		CC=(a*a+b*b-c*c)/(2*a*b);
		A=acos(CA);
		B=acos(CB);
		C=acos(CC);
		S=0.5*sin(B)*a*c;
		s1=0.5*A*r3*r3;
		s2=0.5*B*r2*r2;
		s3=0.5*C*r1*r1;
		s=S-s1-s2-s3;
		printf("Case %d: %.10lf\n",T++,s);
	}
	return 0;
}

LightOJ - 1338 (Crawling in process...)
Time Limit:                                                        1MS                      Memory Limit:                                                        32768KB                      64bit IO Format:                            %lld & %llu                      

Status

Description

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 between1 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

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

Sample Output

Case 1: Yes

Case 2: Yes

Case 3: No

Hint

Source

Problem Setter: Jane Alam Jan
//题意:
给出两个字符串,问一个字符串是否隐藏在另一个字符串中。(可以忽略大小写)
//思路:
直接模拟
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s1[1010],s2[1010];
int ch[1010];
int main()
{
	int t,k=1;
	scanf("%d",&t);
	getchar();
	while(t--)
	{
		memset(s1,0,sizeof(s1));
		memset(s2,0,sizeof(s2));
		memset(ch,0,sizeof(ch));
		gets(s1);
		gets(s2);
		for(int i=0;i<strlen(s1);i++)
		{
			if(s1[i]==' ') continue;
			int op;
			if(s1[i]>='a'&&s1[i]<='z')
			{
				op=s1[i]-'a';
				ch[op]++;
			}
			else if(s1[i]>='A'&&s1[i]<='Z')
			{
				op=s1[i]-'A';
				ch[op]++;
			}
		}
		bool f=false;
		for(int i=0;i<strlen(s2);i++)
		{
			if(s2[i]==' ') continue;
			int op;
			if(s2[i]>='a'&&s2[i]<='z')
			{
				op=s2[i]-'a';
				if(ch[op]!=0)
				ch[op]--;
				else f=true;
			}
			else if(s2[i]>='A'&&s2[i]<='Z')
			{
				op=s2[i]-'A';
				if(ch[op]!=0)
					ch[op]--;
				else 
					f=true;
			}
		}
		if(!f) printf("Case %d: Yes\n",k++);
		else printf("Case %d: No\n",k++);
	}
	return 0;
}

LightOJ - 1387
Time Limit:                                                        2000MS                      Memory Limit: 32768KB64bit IO Format:                            %lld & %llu                      

SubmitStatus

Description

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 addK 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 beN 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

2

4

donate 1000

report

donate 500

report

2

donate 10000

report

Sample Output

Case 1:

1000

1500

Case 2:

10000

Hint

Source

Problem Setter: Jane Alam Jan
Special Thanks: Sohel Hafiz
//题意:
有一个募捐箱,若遇到“donate n”就表示往募捐箱里放n元,遇到“report”表示一个询问,即此时箱子中有多少钱。
#include<cstdio>
#include<set>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int t,k=1;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		printf("Case %d:\n",k++);
		char s[20];
		int sum=0;
		for(int i=0;i<n;i++)
		{
			int x;
			scanf("%s",s);
			if(s[0]=='d'){
				scanf("%d", &x);
				sum+=x;
			}
			else if(s[0]=='r'){
				printf("%d\n",sum);
			}
			
		}
	}
	return 0;
}

LightOJ - 1414
Time Limit:                                                        1000MS                      Memory Limit: 32768KB64bit IO Format:                            %lld & %llu                      

SubmitStatus

Description

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 between2 * 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

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

Sample Output

Case 1: 1

Case 2: 0

Case 3: 1

Case 4: 3

Hint

Source

Problem Setter: Md. Arifuzzaman Arif
Special Thanks: Jane Alam Jan
//题意:
给你两个日期,让你找在这两个日期之间有几个2-29.
#include<cstdio>
#include<set>
#include<queue>
#include<cstring>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
bool js(int y,int r, int yy, int rr)
{
	if(y < yy)return true;
	if(y > yy)return false;
	if(r <= rr)return true;
	return false;
}
bool rn(int y)
{
	if(y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))
		return true;
	return false;
}
map<string, int>mp;
void init()
{
	mp["January"] = 1;
	mp["February"] = 2;
	mp["March"] = 3;
	mp["April"] = 4;
	mp["May"] = 5;
	mp["June"] = 6;
	mp["July"] = 7;
	mp["August"] = 8;
	mp["September"] = 9;
	mp["October"] = 10;
	mp["November"] = 11;
	mp["December"] = 12;
}
void work(int &y1,int &y2,int &m1,int &m2,int &d1,int &d2)
{
	if(y1 > y2)
	{
		swap(y1,y2);
		swap(m1,m2);
		swap(d1,d2);
		return;
	}
	if(y1 < y1)
	{
		return;
	}
	if(m1 > m2)
	{
		swap(y1,y2);
		swap(m1,m2);
		swap(d1,d2);
		return;
	}
	if(m1 < m2)
	{
		return;
	}
	if(d1 > d2)
	{
		swap(y1,y2);
		swap(m1,m2);
		swap(d1,d2);
		return;
	}
}
int find(int y)
{
	int t, t1, t2;
	t = (y - 2000) / 4 + 1;
	t1 = (y - 2000) / 100 + 1;
	t2 = (y - 2000) / 400 + 1;
	return (t - t1 + t2);
}
int main()
{
	int N, kase = 0;
	char s1[15], s2[15];
	int y1, d1, y2, d2, m1, m2;
	scanf("%d", &N);
	init();
	while(N--)
	{
		scanf("%s%d,%d", s1, &d1, &y1);
		scanf("%s%d,%d", s2, &d2, &y2);
		if(mp.count(s1))
		{
			m1 = mp[s1];
		}
		else while(1);
		if(mp.count(s2))
		{
			m2 = mp[s2];
		}
		else while(1);
		if(y1 == y2)
		{
			if(rn(y1) && js(m1,d1, 2, 29) && js(2, 29, m2, d2))
			{
				printf("Case %d: %d\n", ++kase, 1);
				continue;
			}
			printf("Case %d: %d\n", ++kase, 0);
			continue;
		}
		int t = find(y2 - 1) - find(y1);
		if(rn(y1) && js(m1,d1, 2, 29)) t++;
		if(rn(y2) && js(2, 29, m2, d2)) t++;
		printf("Case %d: %d\n", ++kase, t);
	}
	return 0;
}

LightOJ - 1433
Time Limit:                                                        2000MS                      Memory Limit: 32768KB64bit IO Format:                            %lld & %llu                      

SubmitStatus

Description

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 betweenA and B. In the picture, you have to calculate the length of arcACB. You can assume that A and B will always be on the circle centered atO.

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 ofA and (Bx, By) denote the co-ordinate ofB. 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 than10-3 will be ignored.

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

Sample Output

Case 1: 6641.81699183

Case 2: 2295.92880

Case 3: 1616.690325

Case 4: 4155.64159340

Case 5: 5732.01250253

Hint

Source

Problem Setter: Arif Siddiquee
Special Thanks: Jane Alam Jan
//题意:
告诉你圆心坐标,和圆上两点A,B的坐标,问他们俩点之间的较小的一段弧长是多少。
//先求出AB(AB之间的距离)和R,在根据余弦定理求出AB两点所夹的圆心角的cos值,再根据cos值根据弧长公式求出弧长。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#define PI acos(-1.0)
using namespace std;
double S(double x1,double y1,double x2,double y2,double x3,double y3)
{
	return (x2-x3)*(y1-y3)-(y2-y3)*(x1-x3);
}
int main()
{
	int t,T=1;
	scanf("%d",&t);
	while(t--)
	{
		double x0,x1,x2,y0,y1,y2;
		double r,ab,k,b,h,so,C,l,O,s;
		scanf("%lf%lf%lf%lf%lf%lf",&x0,&y0,&x1,&y1,&x2,&y2);
		r=sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
		double r2=(x1-x0)*(x1-x0)+(y1-y0)*(y1-y0);
		ab=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		double ab2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		double co=(2*r2-ab2)/(2*r2);
		O=acos(co);
		if(fabs(ab-2*r)<1e-6)
		{
			l=PI*r;
			printf("Case %d: %lf\n",T++,l);
		}
		else 			
		{
			if(O>PI)
			O=2*PI-O;
			l=O*r;
			printf("Case %d: %lf\n",T++,l);
		}		
	}
	return 0;
}

LightOJ - 1305
Time Limit:                                                        1000MS                      Memory Limit: 32768KB64bit IO Format:                            %lld & %llu                      

SubmitStatus

Description

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

Fig: a parallelogram

Now you are given the co ordinates of A, B and C, you have to find the coordinates ofD 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 ofB and (Cx, Cy) denotes the coordinate ofC. Value of any coordinate lies in the range [-1000, 1000]. And you can assume thatA, 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 ofD and the third one should be the area of the parallelogram.

Sample Input

3

0 0 10 0 10 10

0 0 10 0 10 -20

-12 -10 21 21 1 40

Sample Output

Case 1: 0 10 100

Case 2: 0 -20 200

Case 3: -32 9 1247

Hint

Source

Problem Setter: Jane Alam Jan
//题意:告诉A,B,C三个点的坐标,并且三个点的顺序如图所示,输出D点坐标和平行四边形面积
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#define PI acos(-1.0)
using namespace std;
double S(double x1,double y1,double x2,double y2,double x3,double y3)
{
	return (x2-x3)*(y1-y3)-(y2-y3)*(x1-x3);
}
int main()
{
	int t,T=1;
	scanf("%d",&t);
	while(t--)
	{
		double x,x1,x2,x3,x4,y,y1,y2,y3,y4;
		double s;
		scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
		x=x2-x1;y=y2-y1;
		x4=x3-x;y4=y3-y;
		s=(fabs)(S(x1,y1,x2,y2,x3,y3));
		printf("Case %d: %d %d %d\n",T++,(int)x4,(int)y4,(int)s);
	}
	return 0;
}

LightOJ - 1241
Time Limit:                                                        500MS                      Memory Limit:                                                        32768KB                      64bit IO Format:                            %lld & %llu                      

SubmitStatus

Description

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), wheren denotes the total number of reports of his nose in a certain day. The next line containsn space separated integers denoting the sizes of his nose in that day. If the integers in that line isa1, 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

2

5

2 3 3 3 4

4

2 3 4 5

Sample Output

Case 1: 2

Case 2: 3

Hint

Source

Problem Setter: Jane Alam Jan
//题意:玩偶的鼻子初始的长度是2cm
玩偶的鼻子会因为说谎而变长,但是每说一次谎,它的鼻子最少增加1cm最多增加5cm,现在给你一天中n个时间点的鼻子的长度,问他最少说了几次谎。
//思路:
因为每次最多只能增长5cm,所以如果遇到1      10 这种情况,那么他最少说了两次谎。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int num[1010];
int main()
{
	int t,k=1;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		memset(num,0,sizeof(num));
		int pre=2;
		int cnt=0;
		for(int i=1;i<=n;i++)
		scanf("%d",&num[i]);
		for(int i=1;i<=n;i++)
		{
			if(pre<num[i])
			{
				int d=num[i]-pre;
				cnt+=d/5;
				if(d%5!=0) cnt++;
				pre=num[i];
			}
		}
		printf("Case %d: %d\n",k++,cnt);
	}
	return 0;
}

LightOJ - 1249
Time Limit:                                                        1000MS                      Memory Limit: 32768KB64bit IO Format:                            %lld & %llu                      

SubmitStatus

Description

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 nextn 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 between1 and20. 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' wherex is the name of the chocolate thief, andy is the name of the person from whom the chocolate was taken.

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

Sample Output

Case 1: mun took chocolate from all

Case 2: no thief

Hint

Source

Problem Setter: Jane Alam Jan
//题意:
刚开始时每个人都有一块形状不同,但价值相同的巧克力,但是现在他们中可能有个人偷了另一个同学的巧克力,请找出来这个人并输出着这个人偷了那个人的巧克力。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
	int s[100];
	int sum;
}p[10000];
bool cmp(node s1,node s2)
{
	return s1.sum<s2.sum;
}
int main()
{
	int t,k=1;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		int x,y,z;
		for(int i=0;i<n;i++)
		{
			scanf("%s%d%d%d",p[i].s,&x,&y,&z);
			p[i].sum=x*y*z;
		}
		sort(p,p+n,cmp);
		if(p[0].sum==p[n-1].sum)
		printf("Case %d: no thief\n",k++);
		else
		printf("Case %d: %s took chocolate from %s\n",k++,p[n-1].s,p[0].s);
	}
	return 0;
}

LightOJ - 1261
Time Limit:                                                        2000MS                      Memory Limit: 32768KB64bit IO Format:                            %lld & %llu                      

SubmitStatus

Description

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. AK-SAT problem can be described as follows:

There are n persons, and m objects. Each person makesK 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 leastone of his K wishes is kept. For example, there are 3 persons, 4 objects, andK = 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 n, m, K (1 ≤ n, m, K ≤ 30). Each of the next n lines containsK space separated integers where the ith line denotes the wishes of theith 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 byp 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

2

3 4 2

+1 -2

+3 +4

-3 -1

1 4

1 5 3

+1 -2 +4

2 2 5

Sample Output

Case 1: Yes

Case 2: No

Hint

Source

Problem Setter: Jane Alam Jan
//题意:输入n,m,k; 接下来输入n行,每行k个数。在接下来输入一个p,表示神完成了p个对象,接下来是p个数
表示有n个人,m个对象,每个人有k个愿望。问神完成的p个对象是否可以实现每个人至少一个愿望。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
int mp[50][50];

int vis[1010];
int p;
int n, m, k;
set<int>st;
bool js(){
	for(int i = 1; i <= n; i++){
		int flot  = 0;
		for(int j = 1; j <= k; j++){
			if(st.count(mp[i][j])){
				flot = 1;
				break;
			}
		}
		if(!flot)return false;
	}
	return true;
}
int main(){
	int T, kase = 0;
	scanf("%d", &T);
	while(T--){
		scanf("%d%d%d", &n, &m, &k);
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= k; j++){
				scanf("%d", &mp[i][j]);
			}
		}
		scanf("%d", &p);
		st.clear();
		memset(vis, 0, sizeof(vis));
		int x;
		for(int i = 1; i <= p; i++){
			scanf("%d", &x);
			st.insert(x);
			vis[x] = 1;
		}
		for(int i = 1; i<= m; i++){
			if(!vis[i])st.insert(-i);
		}
		if(js())printf("Case %d: Yes\n", ++kase);
		else
			printf("Case %d: No\n", ++kase);
	}
	return 0;
}

CodeForces - 246A (Crawling in process...)
Time Limit:                                                        1MS                       Memory Limit:                                                        262144KB                       64bit IO Format:                            %I64d & %I64u                      

Status

Description

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 ofn 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 numbern 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 ofn 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.

Sample Input

Input
1
Output
-1

Sample Output

Hint

Source

//题意:输入一个n
根据题中的方法将这n个数按从小到大的顺序排序,问是否可行,可以输出-1,否则输出一个序列证明它是错误的。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){
	int n;
	while(~scanf("%d", &n)){
		if(n == 1 || n == 2){
			printf("-1\n");
			continue;
		}
		for(int i = 1; i <= n-1; i++){
			printf("%d ", i + 1);
		}
		puts("1");
	}
	return 0;
}

CodeForces - 246B
Time Limit:                                                        2000MS                       Memory Limit:                                                        262144KB                       64bit IO Format:                            %I64d & %I64u                      

Status

Description

Polycarpus has an array, consisting of n integersa1, 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 ai,aj(i ≠ j);
  • he simultaneously increases number ai by1 and decreases number aj by1, 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 integersa1, 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.

Sample Input

Input
2
2 1
Output
1
Input
3
1 4 1
Output
3

Sample Output

Hint

Source

//题意:
一个长为 n (1?≤?n?≤?10^5)的序列(元素(|ai|?≤?10^4) ),可以取其中的两个数,一个数 + 1,另一个数就 - 1,可以这样操作无数次,问最后最多能有多少个数是一样的。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int n;
	while(~scanf("%d", &n)){
		int sum = 0, x;
		for(int i = 0; i < n; i++){
			scanf("%d", &x);
			sum += x;
		}
		if(sum%n!=0) n--;
		printf("%d\n", n);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值