暑假训练赛20160727 <贪心,思维,二分图--最小点覆盖>
来源:互联网 发布:武汉人脾气差 知乎 编辑:程序博客网 时间:2024/05/02 00:37
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 coordinates.
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 lines each containing two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases.
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 12 11 20 20 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;}
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 rounds, when all the cards of each player have been chosen, the player who has won the most rounds is the winner of the game.
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 96 1162 63 54 66 65 61 57 56 50 53 480 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;}
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 (i, x, y) , 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(n, m < 100) and k(k < 1000) . The following k lines give the constrains of the k jobs, each line is a triple: i, x, y .
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 11 1 22 1 33 1 44 2 15 2 26 2 37 2 48 3 39 4 30
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;}
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.
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 Y0#
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;}
- 暑假训练赛20160727 <贪心,思维,二分图--最小点覆盖>
- Hdu 6178 Monkeys【树形Dp-最小点覆盖+贪心思维】
- POJ训练计划3041_Asteroids(二分图/最小点覆盖=最大匹配)
- 二分图-最大匹配,最小路径覆盖,最小点覆盖
- POJ 1325二分图,最小点覆盖
- hdu1054 二分图最小点覆盖数
- HDU 4160 二分图最小点覆盖
- poj3041 二分图的最小点覆盖
- POJ 2226 二分图 最小点覆盖
- 二分图最小点覆盖小结
- poj3041 Asteroids 最小点覆盖 二分图
- 二分图的最小点覆盖
- poj1325 二分图的最小点覆盖
- poj3041 二分图最小点覆盖
- POJ3041 Asteroids【二分图最小点覆盖】
- poj 2226 二分图最小点覆盖
- UVa 11419 二分图最小点覆盖
- HDU1528-二分图最小点覆盖
- Mysql学习总结(20)——MySQL数据库优化的最佳实践
- Unity4.3.3 烘焙踩坑
- HDU 5752 Sqrt Bo
- HTTP基本认证(Basic Authentication)的JAVA示例
- HDU1176二维DP
- 暑假训练赛20160727 <贪心,思维,二分图--最小点覆盖>
- property follows cocoa name convention
- HDU 4588
- Android之SurfaceView使用总结
- Android Studio教程:启动时不自动打开项目
- Mysql学习总结(21)——MySQL数据库常见面试题
- linux网络配置
- 随堂笔记7.27:循环-------1
- lintcode在O(1)时间复杂度删除该链表节点。