题意:给你 n 段区间,而且还是不相交的,然后你只能向左扩展左端点,或者向右扩展右端点,然后扩展最少的步数让整数总数能够整除 k。

析:很简单么,只要在记录算一下数量,然后再算出 k 的倍数差多少就行。

代码如下:

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int maxn = 500 + 5;
const int INF = 0x3f3f3f3f;
const int dr[] = {0, 0, 1, -1};
const int dc[] = {1, -1, 0, 0}; int main(){
int k, n;
cin >> n >> k;
LL sum = 0;
int l, r;
for(int i = 0; i < n; ++i){
scanf("%d %d", &l, &r);
sum += r - l + 1;
}
cout << (k - (sum % k)) % k << endl;
return 0;
}

CodeForces 289A Polo the Penguin and Segments (水题)的更多相关文章

  1. CodeForces 288A Polo the Penguin and Strings (水题)

    题意:给定一个字符,让你用前 k 个字符把它排成 n 长度,相邻的字符不能相等,并且把字典序最小. 析:其实很简单么,我们只要多循环ab,就行,最后再把剩下的放上,要注意k为1的时候. 代码如下: # ...

  2. codeforces Gym 100187L L. Ministry of Truth 水题

    L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  3. Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  4. Educational Codeforces Round 14 A. Fashion in Berland 水题

    A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...

  5. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  6. Codeforces Round #190 (Div. 2) 水果俩水题

    后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...

  7. Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告

    对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...

  8. Codeforces Beta Round #14 (Div. 2) C. Four Segments 水题

    C. Four Segments 题目连接: http://codeforces.com/contest/14/problem/C Description Several months later A ...

  9. codeforces B. Polo the Penguin and Matrix 解题报告

    题目链接:http://codeforces.com/problemset/problem/289/B 题目意思:给出一个 n 行 m 列的矩阵和数值 d .通过对矩阵里面的数进行 + d 或者 - ...

随机推荐

  1. MySQL 5.7 坑爹参数 – log_timestamps

    官网原话: This variable was added in MySQL 5.7.2. Before 5.7.2, timestamps in log messages were written ...

  2. Php处理时间的函数

    1,字符串与时间: 例如 $time = strtotime("2007-3-5"); echo date("Y-m-d H:i:s",$time); 2,当前 ...

  3. 第四章 istio快速入门(快速安装)

    4.1 环境介绍 K8s 1.9 以上版本. 4.2 快速部署Istio 下载:  https://github.com/istio/istio/releases/,  下载 1.1.0-snapsh ...

  4. canvas之抒写文字

    <canvas id="canvas" width="500" height="400" style="background ...

  5. Windows C盘文件夹介绍及说明

    Documents and Settings是什么文件? 答案: 是系统用户设置文件夹,包括各个用户的文档.收藏夹.上网浏览信息.配置文件等. 补:这里面的东西不要随便删除,这保存着所有用户的文档和账 ...

  6. ecshop if多条件语句写法

    smarty中的if语句和php中的if语句一样,if必须与/if成对出现.可以使用else和elseif子句. 可以使用条件修饰词:eq.ne.neq.gt.lte.le.gte.ge.is eve ...

  7. [转] c# 操作Word

    来自 风过四季天 的原文 c# 操作Word总结 在医疗管理系统中为保存患者的体检和治疗记录,方便以后的医生或其他人查看.当把数据保存到数据库中,需要新建很多的字段,而且操作很繁琐,于是想 到网页的信 ...

  8. leetcode537

    public class Solution { public string ComplexNumberMultiply(string a, string b) { var aryA = a.Split ...

  9. 「小程序JAVA实战」springboot的后台搭建(31)

    转自:https://idig8.com/2018/08/29/xiaochengxujavashizhanspringbootdehoutaidajian31/ 根据下面的图,我们来建立下对应的sp ...

  10. PHP 性能优化之 PHP-FPM

    简介: PHP-FPM 是一个 PHP FastCGI 管理器,一般 Nginx 上面跑 PHP 程序都会将 PHP 程序丢给 PHP-FPM 来解析.好了,就这样! PHP 5.4 开始集成了 PH ...