Coconuts HDU - 5925 二维离散化 自闭了

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(T10T≤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,C1090<R,C≤109 the second line contains an integer n, the number of bad coconuts, 0n2000≤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

2

3 3
2
1 2
2 1

3 3
1
2 2

Sample Output

Case #1:
2
1 6
Case #2:
1
8
题意

青蛙先生的朋友TanBig非常喜欢吃东西,所以他总是喜欢吃东西。

有一天,TanBig梦想着一片椰子,这个领域看起来像一个有R行和C列的大棋盘。

在田地的每个细胞中,都有一个椰子。 不幸的是,一些椰子变质了。 为了他的健康,

TanBig将按照他只能吃好椰子的规则来吃椰子,并且一次只能吃好椰子的连接成分

(你可以认为坏椰子是障碍,而好的椰子是4- 连接,这意味着单元格(x,y)

中的一个椰子连接到(x-1,y),(x + 1,y),(x,y + 1),(x,y-1)。

现在TanBig想知道他需要多少次吃掉田里所有好吃的椰子,以及每次吃多少椰子(每个4个连接组件的面积)。


其实就是让你求出每一个联通快的大小
因为 R C <= 1e9 所以必须离散化

自闭拉 自闭拉 完全不会啊
只能看题解为生 题目补不完了

二维离散化一下 因为点最多有是一个300*300的矩阵
离散化后用一个cntx,cnty,分别记录每一个格子压缩前的面积
然后就是最裸的DFS计算联通快就行了

注意一下最后的答案要从小到大输出

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <queue>
  4 #include <cmath>
  5 #include <algorithm>
  6 #include <set>
  7 #include <iostream>
  8 #include <map>
  9 #include <stack>
 10 #include <string>
 11 #include <vector>
 12 #define  pi acos(-1.0)
 13 #define  eps 1e-6
 14 #define  fi first
 15 #define  se second
 16 #define  lson l,m,rt<<1
 17 #define  rson m+1,r,rt<<1|1
 18 #define  bug         printf("******\n")
 19 #define  mem(a,b)    memset(a,b,sizeof(a))
 20 #define  fuck(x)     cout<<"["<<x<<"]"<<endl
 21 #define  f(a)        a*a
 22 #define  sf(n)       scanf("%d", &n)
 23 #define  sff(a,b)    scanf("%d %d", &a, &b)
 24 #define  sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
 25 #define  sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
 26 #define  pf          printf
 27 #define  FRE(i,a,b)  for(i = a; i <= b; i++)
 28 #define  FREE(i,a,b) for(i = a; i >= b; i--)
 29 #define  FRL(i,a,b)  for(i = a; i < b; i++)
 30 #define  FRLL(i,a,b) for(i = a; i > b; i--)
 31 #define  FIN         freopen("DATA.txt","r",stdin)
 32 #define  gcd(a,b)    __gcd(a,b)
 33 #define  lowbit(x)   x&-x
 34 #pragma  comment (linker,"/STACK:102400000,102400000")
 35 using namespace std;
 36 typedef long long  LL;
 37 typedef unsigned long long ULL;
 38 const int INF = 0x7fffffff;
 39 const int mod = 1e9 + 7;
 40 const int maxn = 400;
 41 int t, cas = 1, R, C, n, pointx[maxn], pointy[maxn], x[maxn], y[maxn], vis[maxn][maxn];
 42 map<LL, LL>mpx, mpy;
 43 vector<int>cntx, cnty;
 44 int dx[4] = {0, 0, 1, -1};
 45 int dy[4] = {1, -1, 0, 0};
 46 LL sum = 0;
 47 void dfs(int x, int y) {
 48     vis[x][y] = 1;
 49     sum += 1LL * cntx[x] * cnty[y];
 50     for (int i = 0 ; i < 4 ; i++) {
 51         int nx = x + dx[i];
 52         int ny = y + dy[i];
 53         if (nx >= 0 && nx < cntx.size() && ny >= 0 && ny < cnty.size() && !vis[nx][ny]) dfs(nx, ny);
 54     }
 55 }
 56 void init(){
 57     mpx.clear(),mpy.clear();
 58     cntx.clear(),cnty.clear();
 59     mem(vis,0);
 60 }
 61 LL ans[maxn];
 62 int main() {
 63     sf(t);
 64     while(t--) {
 65         sff(R, C);
 66         sf(n);
 67         init();
 68         int cnt1 = 0, cnt2 = 0;
 69         x[cnt1++] = 0, x[cnt1++] = R;
 70         y[cnt2++] = 0, y[cnt2++] = C;
 71         for (int i = 1 ; i <= n ; i++) {
 72             sff(pointx[i], pointy[i]);
 73             x[cnt1++] = pointx[i];
 74             y[cnt2++] = pointy[i];
 75         }
 76         sort(x, x + cnt1);
 77         sort(y, y + cnt2);
 78         cnt1 = unique(x, x + cnt1) - x;
 79         cnt2 = unique(y, y + cnt2) - y;
 80         for (int i = 1 ; i < cnt1 ; i++) {
 81             int len = x[i] - x[i - 1];
 82             if (len > 1) cntx.push_back(len - 1);
 83             cntx.push_back(1);
 84             mpx[x[i]] = cntx.size() - 1;
 85         }
 86         for (int i = 1 ; i < cnt2 ; i++) {
 87             int len = y[i] - y[i - 1];
 88             if (len > 1) cnty.push_back(len - 1);
 89             cnty.push_back(1);
 90             mpy[y[i]] = cnty.size() - 1;
 91         }
 92         for (int i = 1 ; i <= n ; i++)
 93             vis[mpx[pointx[i]]][mpy[pointy[i]]] = 1;
 94         int k = 0;
 95         for (int i = 0 ; i < cntx.size() ; i++) {
 96             for (int j = 0 ; j < cnty.size() ; j++) {
 97                 if (!vis[i][j]) {
 98                     sum = 0;
 99                     dfs(i, j);
100                     ans[k++] = sum;
101                 }
102             }
103         }
104         sort(ans,ans+k);
105         printf("Case #%d:\n", cas++);
106         printf("%d\n",k);
107         for (int i = 0 ; i < k ; i++)
108             printf("%lld%c", ans[i], i == k - 1 ? '\n' : ' ');
109     }
110     return 0;
111 }

 



转载于:https://www.cnblogs.com/qldabiaoge/p/9521208.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解决这个问题King Julien rules the Madagascar island whose primary crop is coconuts. If the price of coconuts is P , then King Julien’s subjects will demand D(P ) = 1200 − 100P coconuts per week for their own use. The number of coconuts that will be supplied per week by the island’s coconut growers is S(p) = 100P. (a) (2 pts) Calculate the equilibrium price and quantity for coconuts. (b) (2 pts) One day, King Julien decided to tax his subjects in order to collect coconuts for the Royal Larder. The king required that every subject who consumed a coconut would have to pay a coconut to the king as a tax. Thus, if a subject wanted 5 coconuts for himself, he would have to purchase 10 coconuts and give 5 to the king. When the price that is received by the sellers is pS, how much does it cost one of the king’s subjects to get an extra coconut for himself? (c) (3 pts) When the price paid to suppliers is pS, how many coconuts will the king’s subjects demand for their own consumption (as a function of pS)? 2 (d) (2 pts) Under the above coconut tax policy, determine the total number of coconuts demanded per week by King Julien and his subjects as a function of pS. (e) (3 pts) Calculate the equilibrium value of pS, the equilibrium total number of coconuts produced, and the equilibrium total number of coconuts consumed by Julien’s subjects. (f) (5 pts) King Julien’s subjects resented paying the extra coconuts to the king, and whispers of revolution spread through the palace. Worried by the hostile atmosphere, the king changed the coconut tax. Now, the shopkeepers who sold the coconuts would be responsible for paying the tax. For every coconut sold to a consumer, the shopkeeper would have to pay one coconut to the king. For this new policy, calculate the number of coconuts being sold to the consumers, the value per coconuts that the shopkeepers got after paying their tax to the king, and the price payed by the consumers.
最新发布
03-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值