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

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

生活随笔

當(dāng)前位置: 首頁(yè) > 人文社科 > 生活经验 >内容正文

生活经验

USACO JANUARY——矩形[rects]

發(fā)布時(shí)間:2023/11/27 生活经验 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 USACO JANUARY——矩形[rects] 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Description

給出N個(gè)矩形(1≤N≤100)和它的長(zhǎng)和寬(不超過(guò)1000),寫(xiě)一個(gè)程序找出最大的K,使得 有K個(gè)矩形滿足層層包含的關(guān)系,即里層的矩形被所有外層的矩形包含.一個(gè)矩形P1包含另一個(gè) 矩形P2,則P2的一邊小于P1的一邊,并且P9的另一邊不超過(guò)P1的另一邊.如果兩個(gè)矩形相同,視為不包含.如2 x 1的矩形被2x2的矩形包含,不被1 x 2的矩形包含. 注意:矩形的順序可以是任意的,且矩形可以旋轉(zhuǎn).

Input

第1行:整數(shù)N. 第2到N+1行:矩形的長(zhǎng)和寬,均為整數(shù).

Output

一行,輸出最大的包含數(shù)K.

Sample Input

4
8 14
16 28
29 12
14 8

Sample Output

2 由于數(shù)據(jù)小,所以可以先把相同的矩形全部刪去,然后處理的時(shí)候,輸入保證長(zhǎng)小于寬,再用長(zhǎng)排序,求寬的最長(zhǎng)不下降序列(本來(lái)可以寫(xiě)成nlogn的,但是想偷個(gè)懶~)
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cmath>
 4 #include<algorithm>
 5 using namespace std;
 6 const int maxn=1005;int maxx=0;
 7 int a[maxn],b[maxn],c[maxn];
 8 bool map[maxn][maxn];
 9 struct node{
10     int l,r;
11 }w[maxn];
12 int n;
13 bool comp(const node &q,const node &e)
14 {
15     if(q.l==e.l)return q.r<e.r;
16     return q.l<e.l;
17 }
18 int main()
19 {
20     freopen("recks.in","r",stdin);
21     freopen("recks.out","w",stdout);
22     scanf("%d",&n);
23     int temp=0;
24     for(int i=1;i<=n;i++)
25     {
26         int x,y;
27         scanf("%d%d",&x,&y);
28         if(map[x][y]==false)
29         {
30             map[x][y]=true;
31             map[y][x]=true;
32             w[++temp].l=x;w[temp].r=y;
33             if(w[temp].l>w[temp].r)swap(w[temp].l,w[temp].r);
34         }
35         else continue;
36     }
37     sort(w+1,w+temp+1,comp);
38     for(int i=1;i<=temp;i++)c[i]=1;
39     for(int i=2;i<=temp;i++)
40     {
41         maxx=0;
42         for(int j=1;j<i;j++)
43         {
44             if(w[i].r>w[j].r&&maxx<c[j]+1)
45             {
46                 maxx=c[j]+1;
47                 c[i]=maxx;
48                 b[i]=j;
49             }
50             else if(w[i].r==w[j].r&&w[i].l!=w[j].l&&maxx<c[j]+1)
51             {
52                 maxx=c[j]+1;
53                 c[i]=maxx;
54                 b[i]=j;
55             }
56         }
57     }
58     int pos=0;maxx=0;
59     for(int i=1;i<=temp;i++)
60     {
61         if(c[i]>maxx)
62         {
63             maxx=c[i];pos=i;
64         }
65     }
66     int ans=0;
67     while(b[pos])
68     {
69         ans++;
70         pos=b[pos];
71     }
72     printf("%d",ans+1);
73     return 0;
74 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/937337156Zhang/p/6025862.html

總結(jié)

以上是生活随笔為你收集整理的USACO JANUARY——矩形[rects]的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

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