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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

【POJ - 3347 】Kadj Squares (计算几何,思维 或 扫描线)

發(fā)布時(shí)間:2023/12/10 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【POJ - 3347 】Kadj Squares (计算几何,思维 或 扫描线) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題干:

In this problem, you are given a sequence?S1,?S2, ...,?Sn?of squares of different sizes. The sides of the squares are integer numbers. We locate the squares on the positive?x-y?quarter of the plane, such that their sides make 45 degrees with?x?and?y?axes, and one of their vertices are on?y=0 line. Let?bi?be the?x?coordinates of the bottom vertex of?Si. First, put?S1?such that its left vertex lies on?x=0. Then, put?S1, (i?> 1) at minimum?bi?such that

  • bi?>?bi-1?and
  • the interior of?Si?does not have intersection with the interior of?S1...Si-1.

?

?

The goal is to find which squares are visible, either entirely or partially, when viewed from above. In the example above, the squares?S1,?S2, and?S4?have this property. More formally,?Si?is visible from above if it contains a point?p, such that no square other than?Siintersect the vertical half-line drawn from?p?upwards.

Input

The input consists of multiple test cases. The first line of each test case is?n?(1 ≤?n?≤ 50), the number of squares. The second line contains?n?integers between 1 to 30, where the?ith number is the length of the sides of?Si. The input is terminated by a line containing a zero number.

Output

For each test case, output a single line containing the index of the visible squares in the input sequence, in ascending order, separated by blank characters.

Sample Input

4 3 5 1 4 3 2 1 2 0

Sample Output

1 2 4 1 3

解題報(bào)告:

? ? ?掃描線忘了啊,不然就試試掃描線了。

AC代碼:

#include<iostream> #include<algorithm> #include<cstdio> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 200 + 5; struct Node {ll l,r;ll s;//邊長(zhǎng) } node[MAX],nnnn[MAX]; ll Abs(ll x) {if(x < 0) x=-x;return x; } int main() {int n;while(~scanf("%d",&n) && n) {for(int i = 1; i<=n; i++) {scanf("%lld",&node[i].s);node[i].l = 0;//先初始化一波for(int j = 1; j<i; j++) {node[i].l = max(node[i].l,node[j].r - (ll)Abs(node[j].s-node[i].s));} node[i].r = node[i].l + 2*node[i].s;}for(int i = 1; i<=n; i++) { // nnnn[i] = node[i];//這個(gè)必須有、、、、 for(int j = 1; j<i; j++) {if(node[i].l < node[j].r && node[i].s < node[j].s) {node[i].l = node[j].r;//即左邊只能看到 這里 這么遠(yuǎn)// }}for(int j = i+1; j<=n; j++) {if(node[i].r > node[j].l && node[i].s < node[j].s) {node[i].r = node[j].l;}}}int flag = 1;for(int i = 1; i<=n; i++) {if(node[i].l < node[i].r) {if(flag) {flag=0;printf("%d",i);}else printf(" %d",i); }}puts("");}return 0 ;}

想問(wèn)為什么這樣就wa????兩者就那一個(gè)地方有區(qū)別(node或者nnnn)

#include<iostream> #include<algorithm> #include<cstdio> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 200 + 5; struct Node {ll l,r;ll s;//邊長(zhǎng) } node[MAX],nnnn[MAX]; ll Abs(ll x) {if(x < 0) x=-x;return x; } int main() {int n;while(~scanf("%d",&n) && n) {for(int i = 1; i<=n; i++) {scanf("%lld",&node[i].s);node[i].l = 0;//先初始化一波for(int j = 1; j<i; j++) {node[i].l = max(node[i].l,node[j].r - (ll)Abs(node[j].s-node[i].s));} node[i].r = node[i].l + 2*node[i].s;}for(int i = 1; i<=n; i++) {nnnn[i] = node[i];//這個(gè)必須有、、、、 for(int j = 1; j<i; j++) {if(node[i].l < node[j].r && node[i].s < node[j].s) {nnnn[i].l = node[j].r;//即左邊只能看到 這里 這么遠(yuǎn)// }}for(int j = i+1; j<=n; j++) {if(node[i].r > node[j].l && node[i].s < node[j].s) {nnnn[i].r = node[j].l;}}}int flag = 1;for(int i = 1; i<=n; i++) {if(nnnn[i].l < nnnn[i].r) {if(flag) {flag=0;printf("%d",i);}else printf(" %d",i); }}puts("");}return 0 ;}

?

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的【POJ - 3347 】Kadj Squares (计算几何,思维 或 扫描线)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。