【POJ2280】Amphiphilic Carbon Molecules——扫描线
来源:互联网 发布:周末网络国债基金公司 编辑:程序博客网 时间:2024/05/16 10:27
Amphiphilic Carbon Molecules
Description
Shanghai Hypercomputers, the world’s largest computer chip manufacturer, has invented a new class of nanoparticles called Amphiphilic Carbon Molecules (ACMs). ACMs are semiconductors. It means that they can be either conductors or insulators of electrons, and thus possess a property that is very important for the computer chip industry. They are also amphiphilic molecules, which means parts of them are hydrophilic while other parts of them are hydrophobic. Hydrophilic ACMs are soluble in polar solvents (for example, water) but are insoluble in nonpolar solvents (for example, acetone). Hydrophobic ACMs, on the contrary, are soluble in acetone but insoluble in water. Semiconductor ACMs dissolved in either water or acetone can be used in the computer chip manufacturing process.
As a materials engineer at Shanghai Hypercomputers, your job is to prepare ACM solutions from ACM particles. You go to your factory everyday at 8 am and find a batch of ACM particles on your workbench. You prepare the ACM solutions by dripping some water, as well as some acetone, into those particles and watch the ACMs dissolve in the solvents. You always want to prepare unmixed solutions, so you first separate the ACM particles by placing an Insulating Carbon Partition Card (ICPC) perpendicular to your workbench. The ICPC is long enough to completely separate the particles. You then drip water on one side of the ICPC and acetone on the other side. The ICPC helps you obtain hydrophilic ACMs dissolved in water on one side and hydrophobic ACMs dissolved in acetone on the other side. If you happen to put the ICPC on top of some ACM particles, those ACMs will be right at the border between the water solution and the acetone solution, and they will be dissolved. Fig.1 shows your working situation.
Fig. 1
Your daily job is very easy and boring, so your supervisor makes it a little bit more challenging by asking you to dissolve as much ACMs into solution as possible. You know you have to be very careful about where to put the ICPC since hydrophilic ACMs on the acetone side, or hydrophobic ACMs on the water side, will not dissolve. As an experienced engineer, you also know that sometimes it can be very difficult to find the best position for the ICPC, so you decide to write a program to help you. You have asked your supervisor to buy a special digital camera and have it installed above your workbench, so that your program can obtain the exact positions and species (hydrophilic or hydrophobic) of each ACM particle in a 2D pictures taken by the camera. The ICPC you put on your workbench will appear as a line in the 2D pictures.
Fig. 2
Input
There will be no more than 10 test cases. Each case starts with a line containing an integer N, which is the number of ACM particles in the test case. N lines then follow. Each line contains three integers x, y, r, where (x, y) is the position of the ACM particle in the 2D picture and r can be 0 or 1, standing for the hydrophilic or hydrophobic type ACM respectively. The absolute value of x, y will be no larger than 10000. You may assume that N is no more than 1000. N = 0 signifies the end of the input and need not be processed. Fig.2 shows the positions of ACM particles and the best ICPC position for the last test case in the sample input.
Output
For each test case, output a line containing a single integer, which is the maximum number of dissolved ACM particles.
Sample Input
3
0 0 0
0 1 0
2 2 1
4
0 0 0
0 4 0
4 0 0
1 2 1
7
-1 0 0
1 2 1
2 3 0
2 1 1
0 3 1
1 4 0
-1 2 0
0
Sample Output
3
3
6
在平面上有一些点,每个点都有0,1其中一个属性。要求用一条直线将平面分成两部分。其中一部分取属性为0的点,另一部分取属性为1的点。若点在直线上全部取走,问最多能取多少个点。
分析:看到题的时候直接敲了一发
O(n3) 的暴力,果断的TLE了,硬伤。
对于v1→v2 我们可以发现我们仅仅需要统计的只是从v1 转换到v2 中点的变化,但是极角排序排序基点是左下角的点,所以对于在选定基点的左下方的点,我们可以将其进行关于基点的对称。
#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <string>#include <queue>#include <stack>#include <vector>#include <iostream>#include <algorithm>using namespace std;const double eps = 1e-6;const int Max = 1100;typedef struct node{ int x,y,op; node(int x = 0,int y = 0):x(x),y(y) {} node operator + (const node &a)const { return node(x+a.x,y+a.y); } node operator - (const node &a)const { return node(x-a.x,y-a.y); }}Point;Point p[Max],s[Max];int dbcmp(double x)//精度控制{ if(fabs(x)<eps) return 0; return x>0?1:-1;}double Cross(node a, node b) // 叉积{ return a.x*b.y-a.y*b.x;}double Dot(node a,node b) //点积{ return a.x*b.x+a.y*b.y;}double Distance(node a) //计算距离{ return a.x*a.x+a.y*a.y;}node p0;bool cmp(node a,node b) //比较函数{ int ans = dbcmp(Cross(a,b)); if(ans>0) { return true; } else if(ans==0) { return Distance(a)>=Distance(b); } return false;}int n;int main(){ while(scanf("%d",&n)&&n) { for(int i = 0;i<n;i++) { scanf("%d %d %d",&p[i].x,&p[i].y,&p[i].op); } int ans = 0; for(int i = 0;i<n;i++) { int sum1 = 0,sum2 = 0; for(int j = 0;j<n;j++) { s[j].x = p[j].x -p[i].x; s[j].y = p[j].y-p[i].y; s[j].op = p[j].op; if(s[j].y<0||(s[j].y==0&&s[j].x<0)) { s[j].y = -s[j].y; s[j].x = -s[j].x; s[j].op = (1+s[j].op)%2; } if(s[j].op) sum1++; else sum2++; } sort(s,s+n,cmp); int ans1 = 0,ans2 = 0; int num1 = 0,num2 = 0; int j = 0 ,t =0 ; for(j = 0;j<n;j++) { if(s[j].op) ans1++; else ans2++; while(dbcmp(Cross(s[j],s[t]))) { if(s[t].op) num1++; else num2++; t++; } ans = max(ans,max(sum1-ans1+num2,sum2-ans2+num1)+(ans1-num1+ans2-num2)); } } printf("%d\n",ans); } return 0;}
- 【POJ2280】Amphiphilic Carbon Molecules——扫描线
- POJ2280 Amphiphilic Carbon Molecules
- poj2280--Amphiphilic Carbon Molecules(扫描线+极角排序+转换坐标)
- UVa 1606 Amphiphilic Carbon Molecules——极角扫描
- POJ 2280 Amphiphilic Carbon Molecules 极角排序 + 扫描线
- 【高效算法设计——扫描法】Amphiphilic Carbon Molecules 极角排序
- uva1606 Amphiphilic Carbon Molecules
- Amphiphilic Carbon Molecules
- UVA1606 Amphiphilic Carbon Molecules
- 1606 - Amphiphilic Carbon Molecules
- Amphiphilic Carbon Molecules UVA
- uva1606 Amphiphilic Carbon Molecules
- 【POJ 2280】Amphiphilic Carbon Molecules(极角排序+坐标转换+扫描线)
- [极角排序 扫描法]UVa1606 - Amphiphilic Carbon Molecules
- UVa UVA1606 Amphiphilic Carbon Molecules
- Uva1606 Amphiphilic Carbon Molecules【例题8-6】【极角扫描法】【不懂!】
- Shanghai 2004 ( UVALive 3259) Amphiphilic Carbon Molecules
- POJ 2280 && HDU 1661 Amphiphilic Carbon Molecules
- java8新语法学习
- 线段树 2016.4.15
- JDK安装与环境变量配置
- maven用用overlays合并多个war
- bzoj3261: 最大异或和
- 【POJ2280】Amphiphilic Carbon Molecules——扫描线
- 网站上面的文件下载次数如何统计?
- 占座中
- 【HDU1542】Atlantis【线段树】【矩形面积并】
- c++ locale类
- 【c语言】编写一个函数new,对n个字符开辟连续的存储空间,此函数应返回一个指针(地址),指向字符串开始的空间
- 医学图像处理笔记(3)
- 华为2016实习生上机题
- Codeforces 660B Seating On Bus 【模拟】