国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

D - Coconuts HDU - 5925

2019-11-08 18:49:44
字體:
來源:轉載
供稿:網友

TanBig, a friend of Mr. Frog, likes eating very much, so he always has dreams about eating. One day, TanBig dreams of a field of coconuts, and the field looks like a large chessboard which has R rows and C columns. In every cell of the field, there is one coconut. Unfortunately, some of the coconuts have gone bad. For sake of his health, TanBig will eat the coconuts following the rule that he can only eat good coconuts and can only eat a connected component of good coconuts one time(you can consider the bad coconuts as barriers, and the good coconuts are 4-connected, which means one coconut in cell (x, y) is connected to (x - 1, y), (x + 1, y), (x, y + 1), (x, y - 1). Now TanBig wants to know how many times he needs to eat all the good coconuts in the field, and how many coconuts he would eat each time(the area of each 4-connected component). InputThe first line contains apositiveinteger T(T≤10T≤10) which denotes the test cases. T test cases begin from the second line. In every test case, the first line contains two integers R and C, 0<R,C≤1090<R,C≤109 the second line contains an integer n, the number of bad coconuts, 0≤n≤2000≤n≤200 from the third line, there comes n lines, each line contains two integers, xixi and yiyi, which means in cell(xi,yixi,yi), there is a bad coconut. It is guaranteed that in the input data, the first row and the last row will not have bad coconuts at the same time, the first column and the last column will not have bad coconuts at the same time. OutputFor each test case, output "Case #x:" in the first line, where x denotes the number of test case, one integer k in the second line, denoting the number of times TanBig needs, in the third line, k integers denoting the number of coconuts he would eat each time, you should output them in increasing order.Sample Input
23 321 22 13 312 2Sample Output
Case #1:21 6Case #2:18

題意:求連通塊的個數,以及每個聯通塊中點的個數。

思路:范圍很大,所以要離散化坐標軸。

給出的是障礙點。那么不是障礙的點離散化之后都會是一個矩形。搜索每個點的時候我們每次加上矩形的面積,最后求出總和。

#include <bits/stdc++.h>using namespace std;const int MAXN=300;bool vis[MAXN][MAXN];int x[MAXN],y[MAXN];map<int,int>x_cnt,y_cnt;int pointx[MAXN],pointy[MAXN];long long ans[MAXN];vector<long long>lenx,leny;int n,m,k;long long sum;int dx[4]= {0,0,1,-1};int dy[4]= {1,-1,0,0};void dfs(int x,int y){    vis[x][y]=1;    sum+=lenx[x]*leny[y];    for(int i=0; i<4; ++i)    {        int nx=x+dx[i];        int ny=y+dy[i];        if(nx>=0&&nx<int(lenx.size())&&ny>=0&&ny<int(leny.size())&&!vis[nx][ny])        {            dfs(nx,ny);        }    }}void init(){    x_cnt.clear();    y_cnt.clear();    lenx.clear();    leny.clear();    memset(vis,0,sizeof(vis));}int main(){    int t;    int i,j;    scanf("%d",&t);    for(int tt=1; tt<=t; ++tt)    {        init();        scanf("%d%d",&n,&m);        int cnt1=0,cnt2=0;        x[cnt1++]=y[cnt2++]=0;        x[cnt1++]=n;        y[cnt2++]=m;        scanf("%d",&k);        for(i=0; i<k; ++i)        {            scanf("%d%d",&pointx[i],&pointy[i]);            x[cnt1++]=pointx[i];            y[cnt2++]=pointy[i];        }        sort(x,x+cnt1);        sort(y,y+cnt2);        cnt1=unique(x,x+cnt1)-x;        cnt2=unique(y,y+cnt2)-y;        for(i=1; i<cnt1; ++i)        {            int len=x[i]-x[i-1];            if(len>1)            {                lenx.push_back(len-1);//不包括障礙點,空白的點連接起來的長度            }            lenx.push_back(1);//障礙點單獨算,長度必定為1            x_cnt[x[i]]=lenx.size()-1;        }        for(i=1; i<cnt2; ++i)        {            int len=y[i]-y[i-1];            if(len>1)            {                leny.push_back(len-1);//不包括障礙點,空白的點連接起來的長度            }            leny.push_back(1);//障礙點單獨算,長度必定為1            y_cnt[y[i]]=leny.size()-1;        }        for(i=0; i<k; ++i)        {            vis[x_cnt[pointx[i]]][y_cnt[pointy[i]]]=1;        }        int cnt=0;        for(i=0; i<int(lenx.size()); ++i)        {            for(j=0; j<int(leny.size()); ++j)            {                if(!vis[i][j])                {                    sum=0;                    dfs(i,j);                    ans[cnt++]=sum;                }            }        }        sort(ans,ans+cnt);        PRintf("Case #%d:/n",tt);        printf("%d/n",cnt);        for(i=0; i<cnt; ++i)printf(i==cnt-1?"%I64d/n":"%I64d ",ans[i]);    }    return 0;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 云龙县| 昌乐县| 布拖县| 平罗县| 扬州市| 宣武区| 徐汇区| 丹寨县| 安达市| 达州市| 泾源县| 龙陵县| 高雄县| 藁城市| 永和县| 旅游| 邯郸县| 顺义区| 凤庆县| 中超| 临朐县| 江陵县| 玉树县| 边坝县| 措勤县| 朝阳区| 新昌县| 大新县| 阿勒泰市| 昌乐县| 涞源县| 乌什县| 龙游县| 定结县| 保康县| 基隆市| 兴海县| 香格里拉县| 普宁市| 北碚区| 深水埗区|