Radar Installation


Time Limit: 3000MS

 

 

64bit IO Format: %lld & %llu


Submit​ Status​ uDebug


Description





Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d

We use Cartesian coordinate system, defining the coasting is the x -axis. The sea side is above x -axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x - y





​Input​​ 

The input consists of several test cases. The first line of each case contains two integers n(1n1000) and d , where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n

The input is terminated by a line containing pair of zeros.

​Output​​ 

For each test case output one line consisting of the test case number followed by the minimal number of radar installations needed. `-1' installation means no solution for that case.

​Sample Input​​ 


3 21 2 -3 1 2 1 1 2 0 2 0 0


​Sample Output​​ 


Case 1: 2Case 2: 1





代码:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node{
double l,r;
}dian[1100];
bool cmp(node xx,node yy)
{
return xx.r<yy.r;
}
int main()
{
int n;int ca=1;
double x,y,d,pp;
while (scanf("%d%lf",&n,&d),n+d)
{
bool fafe=false;
for (int i=0;i<n;i++)
{
scanf("%lf%lf",&x,&y);
if (y>d)
fafe=true;
else
{
pp=sqrt(d*d-y*y);
dian[i].l=x-pp;
dian[i].r=x+pp;
}

}
if (fafe)
{
printf("Case %d: -1\n",ca++);
continue;
}
sort(dian,dian+n,cmp);
int s=1;
double di=dian[0].r;
for (int i=1;i<n;i++)
if (dian[i].l>di)
{
di=dian[i].r;
s++;
}
printf("Case %d: %d\n",ca++,s);
}
return 0;
}




​Game Prediction​


Time Limit: 3000MS

 

 

64bit IO Format: %lld & %llu


​Submit​​​ ​​Status​​​ ​​uDebug​


Description


​​


Suppose there are M people, including you, playing a special card game. At the beginning, each player receives N cards. The pip of a card is a positive integer which is at most N*M . And there are no two cards with the same pip. During a round, each player chooses one card to compare with others. The player whose card with the biggest pip wins the round, and then the next round begins. After N

Given your cards received at the beginning, write a program to tell the maximal number of rounds that you may at least win during the whole game.


Output


For each test case, output a line consisting of the test case number followed by the number of rounds you will at least win during the game.


Sample Input


2 51 7 2 10 9 6 11 62 63 54 66 65 61 57 56 50 53 48 0 0


Sample Output


Case 1: 2Case 2: 4



代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool cmp(int xx,int yy)
{return xx>yy;}
int main()
{
int m,n;
int shu[4010];int ca=1;
while (scanf("%d%d",&m,&n),m+n)
{
for (int i=0;i<n;i++)
scanf("%d",&shu[i]);
sort(shu,shu+n,cmp);
int ki=n*m;int s=0;
for (int i=0;i<n;i++)
{
if (shu[i]==ki)
{
ki--;
s++;
}
else
{
ki-=2;
}
}
printf("Case %d: %d\n",ca++,s);
}
return 0;
}




G - Machine Schedule

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

Submit  ​​Status​​​  ​​Practice​​​  ​​UVALive 2523​​​  ​​uDebug​


Description


​​


As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of the constraints that must be satisfied and the type of schedule desired. Here we consider a 2-machine scheduling problem.

There are two machines A and B . Machine A has n kinds of working modes, which is called mode0 , mode1 , ... , moden-1 , likewise machine B has m kinds of working modes, mode0 , mode1 , ... , modem-1 . At the beginning they are both work at mode0

For k jobs given, each of them can be processed in either one of the two machines in particular mode. For example, job 0 can either be processed in machine A at mode3 or in machine B at mode4 , job 1 can either be processed in machine A at mode2 or in machine B atmode4 , and so on. Thus, for job i, the constraint can be represent as a triple (ixy) , which means it can be processed either in machineA at modex , or in machine B at modey

Obviously, to accomplish all the jobs, we need to change the machine's working mode from time to time, but unfortunately, the machine's working mode can only be changed by restarting it manually. By changing the sequence of the jobs and assigning each job to a suitable machine, please write a program to minimize the times of restarting machines.


Input


The input file for this program consists of several configurations. The first line of one configuration contains three positive integers: n ,m(nm < 100) and k(k < 1000) . The following k lines give the constrains of the k jobs, each line is a triple: ixy

The input will be terminated by a line containing a single zero.


Output


The output should be one integer per line, which means the minimal times of restarting machine.


Sample Input


5 5 100 1 1 1 1 2 2 1 3 3 1 4 4 2 1 5 2 2 6 2 3 7 2 4 8 3 3 9 4 3 0


Sample Output


3





好神奇的二分图-----最小点覆盖=最大匹配数




最大匹配数:在所有的顶点都两两被不重复的线连接起来时的边数


二分图求最小顶点覆盖:即用最少的顶点个数可以让每条边至少与其中一个点关联




代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,k;
int cover[120];
int qian[120],dis[120][120];
int find(int xx)
{
for (int i=1;i<m;i++)
{
if (dis[xx][i]&&!cover[i])
{
cover[i]=1;
if (!qian[i]||find(qian[i]))
{
qian[i]=xx;
return true;
}
}
}
return false;
}
int main()
{
while (scanf("%d",&n),n)
{
memset(dis,0,sizeof(dis));
scanf("%d%d",&m,&k);
for (int i=0;i<k;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if (b&&c)
dis[b][c]=1;
}
int s=0;memset(qian,0,sizeof(qian));
for (int i=1;i<n;i++)
{
memset(cover,0,sizeof(cover));
if (find(i))
s++;
}
printf("%d\n",s);
}
return 0;
}





​Mileage Bank​


Time Limit: 3000MS

 

 

64bit IO Format: %lld & %llu


​Submit​​​ ​​Status​​​ ​​uDebug​


Description


​​


Mileage program of ACM (Airline of Charming Merlion) is really nice for the travelers flying frequently. Once you complete a flight with ACM, you can earn ACMPerk miles in your ACM Mileage Bank depended on mileage you actual fly. In addition, you can use the ACMPerk mileage in your Mileage Bank to exchange free flight ticket of ACM in future.

The following table helps you calculate how many ACMPerk miles you can earn when you fly on ACM.



When you fly ACM

Class Code

You'll earn

First Class

F

Actual mileage + 100% mileage Bonus

Business Class

B

Actual mileage + 50% mileage Bonus

Economy Class

Y

 

1-500 miles

 

500 miles

500+ miles

 

Actual mileage


It's shown that your ACMPerk mileage consists of two parts. One is your actual flight mileage (the minimum ACMPerk mileage for Economy Class for one flight is 500 miles), the other is the mileage bonus (its accuracy is up to 1 mile) when you fly in Business Class and First Class. For example, you can earn 1329 ACMPerk miles, 1994 ACMPerk miles and 2658 ACMPerk miles for Y, B or F class respectively for the fly from Beijing to Tokyo (the actual mileage between Beijing and Tokyo is 1329 miles). When you fly from Shanghai to Wuhan, you can earn ACMPerk 500 miles for economy class and ACMPerk 650 miles for business class (the actual mileage between Shanghai and Wuhan is 433 miles).

Your task is to help ACM build a program for automatic calculation of ACMPerk mileage.


Output


Output the summary of ACMPerk mileages for each test case, one per line.


Sample Input


Beijing Tokyo 1329 FShanghai Wuhan 433 Y 0 #


Sample Output


3158



代码“:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
char ch[2000];
while (scanf("%s",ch),ch[0]!='#')
{
double s=0,a;
char pp[5];
scanf("%s%lf%s",ch,&a,pp);
if (pp[0]=='F')
s+=2*a;
else if (pp[0]=='B')
s+=1.5*a;
else if (a<500)
s+=500;
else
s+=a;
while (scanf("%s",ch),ch[0]!='0')
{
scanf("%s%lf%s",ch,&a,pp);
if (pp[0]=='F')
s+=2*a;
else if (pp[0]=='B')
s+=1.5*a;
else if (a<500)
s+=500;
else
s+=a;
}
printf("%d\n",int(s+0.5));
}
return 0;
}