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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

省赛组队赛5

發布時間:2025/3/16 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 省赛组队赛5 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

A題:Mountain Climbing?http://acm.fzu.edu.cn/problem.php?pid=2160

比賽時一直在看其他題,沒有仔細想這道題。

做這道題之前,首先要知道:

已知三個點的坐標: A(x1,y1), B(x2,y2), C(x3,y3)
1.若(x1-x3)*(y2-y3) - (y1-y3)*(x2-x3) > 0,則C在線段AB的上方;
2.若(x1-x3)*(y2-y3) - (y1-y3)*(x2-x3) < 0,則C在線段AB的下方;
3.若(x1-x3)*(y2-y3) - (y1-y3)*(x2-x3) == 0,則C在線段AB上。


這樣,我們就可以從后往前遍歷,依次找從當前點開始能夠和距離當前點最遠的那座山連接繩索,因為后邊的已經求出來了,所以當前點的時間為找到的最遠點的的時間加1。

還有一個要注意的地方:題目中山的高度為10^8,在相乘時會超int,所以應該用64位整數。

#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; const int N = 1e5 + 10; struct node {__int64 x;__int64 y; }a[N]; int next[N], dp[N];bool judge(node a0, node a1, node a2) {__int64 k = (a0.x - a2.x) * (a1.y - a2.y) - (a0.y - a2.y) * (a1.x - a2.x);if(k < 0) return 1;return 0; }int main() {int n, i, T, cas = 0;scanf("%d",&T);while(T--){scanf("%d",&n);for(i = 1; i <= n; i++)scanf("%I64d%I64d",&a[i].x, &a[i].y);memset(next, 0, sizeof(next));dp[n] = 0;dp[n-1] = 1;next[n-1] = n;for(i = n - 2; i > 0; i--){int tmp = i + 1;while(tmp != n && judge(a[next[tmp]], a[tmp], a[i])){tmp = next[tmp];}next[i] = tmp;dp[i] = dp[tmp] + 1;}printf("Case#%d: ",++cas);for(i = 1; i < n; i++)printf("%d ", dp[i]);printf("%d\n", dp[n]);}return 0; }

D題:多米諾骨牌?http://acm.fzu.edu.cn/problem.php?pid=2163

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std;const int N = 1e5 + 10; struct node {int x; //位置坐標int h; //高度int id; //編號int maxr; //最右邊端點int ans; //能推倒的個數 }a[N];bool comp1(node a1, node a2) {return a1.x < a2.x; } bool comp2(node a1, node a2) {return a1.id < a2.id; }int main() {int n, i, j;while(~scanf("%d",&n)){for(i = 0; i < n; i++){scanf("%d%d",&a[i].x, &a[i].h);a[i].id = i;a[i].ans = 1;a[i].maxr = a[i].x + a[i].h - 1;}sort(a, a+n, comp1);for(i = n - 2; i >= 0; i--){j = i + 1;int r = a[i].maxr;while(1){if(j >= n || a[j].x > r) break;a[i].ans += a[j].ans;r = max(a[j].maxr, r); //更新第i個骨牌能推倒的骨牌的最右邊端點j += a[j].ans; //連續的a[j].ans個都能推倒,所以可以直接往后跳}a[i].maxr = r; }sort(a, a+n, comp2);for(i = 0; i < n - 1; i++)printf("%d ",a[i].ans);printf("%d\n",a[n-1].ans);}return 0; }

總結

以上是生活随笔為你收集整理的省赛组队赛5的全部內容,希望文章能夠幫你解決所遇到的問題。

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