JZOJ 3382. 【NOIP2013模拟】七夕祭
Description
TYVJ七夕祭和11区的夏祭的形式很像。矩形的祭典会场由N排M列共计N×M个摊点组成。虽然摊点种类繁多,不过cl只对其中的一部分摊点感兴趣,比如章鱼烧、苹果糖、棉花糖、射的屋……什么的。Vani预先联系了七夕祭的负责人zhq,希望能够通过恰当地布置会场,使得各行中cl感兴趣的摊点数一样多,并且各列中cl感兴趣的摊点数也一样多。
不过zhq告诉Vani,摊点已经随意布置完毕了,如果想满足cl的要求,唯一的调整方式就是交换两个相邻的摊点。两个摊点相邻,当且仅当他们处在同一行或者同一列的相邻位置上。由于zhq率领的TYVJ开发小组成功地扭曲了空间,每一行或每一列的第一个位置和最后一个位置也算作相邻。现在Vani想知道他的两个要求最多能满足多少个。在此前提下,至少需要交换多少次摊点。
Input
接下来T行,每行两个整数x, y,表示cl对处在第x行第y列的摊点感兴趣。
Output
如果输出的字符串不是impossible, 接下来输出最小交换次数,与字符串之间用一个空格隔开。
Sample Input
样例输入1
2 3 4
1 3
2 1
2 2
2 3
样例输入2
3 3 3
1 3
2 2
2 3
Sample Output
样例输出1
row 1
样例输出2
both 2
Data Constraint
对于70% 的数据,N, M≤1000。
对于100% 的数据,1≤N, M≤100000,0≤T≤min(NM, 100000),1≤x≤N,1≤y≤M。
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#define N 100007
using namespace std;
long long n, m, k, r[N], c[N], rs[N], cs[N], ans; long long read()
{
long long s = ;
char ch = getchar();
while (ch < '' || ch > '') ch = getchar();
while (ch >= '' && ch <= '') s = s * + ch - '', ch = getchar();
return s;
} int abs(int a) {if (a < ) return -a; return a;} void work1()
{
long long s = k / m;
for (int i = ; i <= m; i++)
cs[i] += cs[i - ] + (c[i] - s);
sort(cs + , cs + m + );
long long sum = ;
for (int i = ; i <= m; i++)
sum += abs(cs[i] - cs[( + m) / ]);
ans += sum;
} void work2()
{
long long s = k / n;
for (int i = ; i <= n; i++)
rs[i] += rs[i - ] + (r[i] - s);
sort(rs + , rs + n + );
long long sum = ;
for (int i = ; i <= n; i++)
sum += abs(rs[i] - rs[( + n) / ]);
ans += sum;
} int main()
{
n = read(), m = read(), k = read();
int x, y;
for (int i = ; i <= k; i++)
{
x = read(), y = read();
r[x]++, c[y]++;
}
if (k % n == && k % m == )
{
work1();
work2();
printf("both ");
printf("%lld", ans);
}
else if (k % n == )
{
work2();
printf("row ");
printf("%lld", ans);
}
else if (k % m == )
{
work1();
printf("column ");
printf("%lld", ans);
}
else printf("impossible");
}
JZOJ 3382. 【NOIP2013模拟】七夕祭的更多相关文章
- [JZOJ3382] [NOIP2013模拟] 七夕祭 解题报告
Description 七夕节因牛郎织女的传说而被扣上了「情人节」的帽子.于是TYVJ今年举办了一次线下七夕祭.Vani同学今年成功邀请到了cl同学陪他来共度七夕,于是他们决定去TYVJ七夕祭游玩. ...
- JZOJ【NOIP2013模拟联考14】隐藏指令
JZOJ[NOIP2013模拟联考14]隐藏指令 题目 Description 在d维欧几里得空间中,指令是一个长度为2N的串.串的每一个元素为d个正交基的方向及反方向之一.例如,d = 1时(数轴) ...
- 【NOIP2013模拟】七夕祭
题目描述七夕节因牛郎织女的传说而被扣上了「情人节」的帽子.于是TYVJ今年举办了一次线下七夕祭.Vani同学今年成功邀请到了cl同学陪他来共度七夕,于是他们决定去TYVJ七夕祭游玩. TYVJ七夕祭和 ...
- JZOJ 3383. 【NOIP2013模拟】太鼓达人
3383. [NOIP2013模拟]太鼓达人 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Detailed Limits ...
- JZOJ 3493. 【NOIP2013模拟联考13】三角形
3493. [NOIP2013模拟联考13]三角形(triangle) (File IO): input:triangle.in output:triangle.out Time Limits: 10 ...
- JZOJ 3487. 【NOIP2013模拟联考11】剑与魔法(dragons)
3487. [NOIP2013模拟联考11]剑与魔法(dragons) (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB De ...
- JZOJ 3470. 【NOIP2013模拟联考8】最短路(path)
470. [NOIP2013模拟联考8]最短路(path) (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Detailed ...
- JZOJ 3388. 【NOIP2013模拟】绿豆蛙的归宿
3388. [NOIP2013模拟]绿豆蛙的归宿 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Detailed Limi ...
- JZOJ 3463. 【NOIP2013模拟联考5】军训
3463. [NOIP2013模拟联考5]军训(training) (Standard IO) Time Limits: 2000 ms Memory Limits: 262144 KB Deta ...
随机推荐
- 性能测试学习第五天_loadrunner概述
1.为什么要进行性能测试(性能测试贯穿于软件生命周期) The failure of a mission-critical application can be costly. Assure perf ...
- prototype 以及 constructor 属性的理解
1 为什么 xx.constructor.prototype 可以访问到当前对象的原型. 'str'.constructor.prototype 'str'.constructor 指向当前 ...
- EF增删查改加执行存储过程和sql语句,多种方法汇总
ActionUrl c = new ActionUrl() { ActionName="test", RequestUrl="/123/123", SubTim ...
- ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第十四天(非原创)
文章大纲 一.淘淘商城总体架构介绍二.淘淘商城重要技术点总结三.项目常见面试题四.项目学习(all)资源下载五.参考文章 一.淘淘商城总体架构介绍 1. 功能架构 2. 技术选型 (1)Sprin ...
- 提高jquery加载速率(有cdn就加载,没有就加载本地)
<!-- Adds google cdn reference --> <script src="https://cdn.bootcss.com/jquery/3.2.1/j ...
- vue-extend 选项
vue-extend 选项 mixins 和extend 很相似,但有区别: var extendNews={ //后来的内容用变量接收 updated:function(){ console.log ...
- 50道CSS基础面试题(附答案)
1 介绍一下标准的CSS的盒子模型?与低版本IE的盒子模型有什么不同的? 标准盒子模型:宽度=内容的宽度(content)+ border + padding + margin低版本IE盒子模型:宽度 ...
- 移动端toast 提示,HTML css 全屏垂直水平居中
- Eucalyptus镜像管理
1.前言 Elastic Utility Computing Architecture for Linking Your Programs To Useful Systems (Eucalyptus) ...
- centos7 初体验
centos7 https://linux.cn/tag-RHCSA%7CRHCSA.html #/etc/sysconfig/network NETWORKING=yes GATEWAY=192.1 ...