日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UVA - 1606 Amphiphilic Carbon Molecules

發布時間:2024/4/11 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UVA - 1606 Amphiphilic Carbon Molecules 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:平面上有n個點n<=1000,分為黑白兩個點,用一條線分開,使得兩邊兩個點(只能單獨取黑或白)最大。

分析:這題首先肯定是用枚舉,涉及到角度精確的問題,和巨人與鬼很相似。參考了作者的方法,還是orz。

int L = 0, R = 0, cnt = 2;while(L < k) {if(R == L) { R = (R+1)%k; cnt++; } // empty intervalwhile(R != L && Left(p[L], p[R])) { R = (R+1)%k; cnt++; } // stop when [L,R] spans across > 180 degreescnt--;L++;ans = max(ans, cnt);}

這是代碼中最精華的一部分。巧妙地將黑白兩點的區分和分割問題用叉積解決了。想到應該不難,但是還是有些細節方面的處理。

作者完整代碼:

#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespace std;const int maxn = 1000 + 5;struct Point {int x, y;double rad; // with respect to current pointbool operator<(const Point &rhs) const {return rad < rhs.rad;}}op[maxn], p[maxn];int n, color[maxn];// from O-A to O-B, is it a left turn?bool Left(Point A, Point B) {return A.x * B.y - A.y * B.x >= 0;}int solve() {if(n <= 2) return 2;int ans = 0;// pivot pointfor(int i = 0; i < n; i++) {int k = 0;// the list of other point, sorted in increasing order of radfor(int j = 0; j < n; j++)if(j != i) {p[k].x = op[j].x - op[i].x;p[k].y = op[j].y - op[i].y;if(color[j]) { p[k].x = -p[k].x; p[k].y = -p[k].y; }p[k].rad = atan2(p[k].y, p[k].x);k++;}sort(p, p+k);// sweeping. cnt is the number of points whose rad is between p[L] and p[R]int L = 0, R = 0, cnt = 2;while(L < k) {if(R == L) { R = (R+1)%k; cnt++; } // empty intervalwhile(R != L && Left(p[L], p[R])) { R = (R+1)%k; cnt++; } // stop when [L,R] spans across > 180 degreescnt--;L++;ans = max(ans, cnt);}}return ans;}int main() {while(scanf("%d", &n) == 1 && n) {for(int i = 0; i < n; i++)scanf("%d%d%d", &op[i].x, &op[i].y, &color[i]);printf("%d\n", solve());}return 0;}

?

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的UVA - 1606 Amphiphilic Carbon Molecules的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。