BZOJ3032/COGS1045 [Nescafé 18] 七夕祭 【环形均分纸牌】

http://wulala.logdown.com/posts/208710-divide-the-problem-and-shared-the-ring-solitaire-solitaire-questions

其实是在书上看的,然而懒得打那么多字了= =

 1 /* ***********************************************
 2 Author        :BPM136
 3 Created Time  :2018/7/15 15:02:24
 4 File Name     :3032.cpp
 5 ************************************************ */
 6 
 7 #include<iostream>
 8 #include<cstdio>
 9 #include<algorithm>
10 #include<cstdlib>
11 #include<cmath>
12 #include<cstring>
13 #include<vector>
14 using namespace std;
15 
16 typedef long long ll;
17 
18 const int N = 200005;
19 
20 int A[N];
21 ll S[N];
22 int n,m,k;
23 int X[N];
24 int Y[N];
25 
26 ll calc(int num,int aver,int a[]) {
27     for(int i=1;i<=num;i++) A[i]=a[i]-aver;
28     for(int i=1;i<=num;i++) S[i]=S[i-1]+A[i];
29     sort(S+1,S+num+1);
30     ll ret=0;
31     for(int i=1;i<=num;i++) ret+=abs(S[i]-S[(num+1)>>1]);
32     return ret;
33 }
34 
35 int main() {
36     freopen("tanabata.in","r",stdin);
37     freopen("tanabata.out","w",stdout);
38     scanf("%d%d%d",&n,&m,&k);
39     for(int i=1;i<=k;i++) {
40         int x,y;
41         scanf("%d%d",&x,&y);
42         X[x]++;
43         Y[y]++;
44     }
45     ll ans_x=0,ans_y=0;
46     int flag_x=0,flag_y=0;
47     if(k%n==0) {
48         flag_x=1;
49         ans_x=calc(n,k/n,X);
50     }
51     if(k%m==0) {
52         flag_y=1;
53         ans_y=calc(m,k/m,Y);
54     }
55 
56     if(flag_x && flag_y) {
57         cout<<"both"<<' '<<ans_x+ans_y<<endl;
58         return 0;
59     } 
60     if(flag_x) {
61         cout<<"row"<<' '<<ans_x<<endl;
62         return 0;
63     }
64     if(flag_y) {
65         cout<<"column"<<' '<<ans_y<<endl;
66         return 0;
67     }
68     cout<<"impossible"<<endl;
69     return 0;
70 }
View Code

 

转载于:https://www.cnblogs.com/MyGirlfriends/p/9313670.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值