题意:给你 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. PDA后台运行、安装程序

    ////启动最新版本安装(后台安装模式),结束更新程序            //string cabPath = @"\Application Data\QY.DDM.PDA.CAB&qu ...

  2. Mac Terminal终端光标的快捷键操作

    2016年08月18日 18:26:06 阅读数:4217 Mac Terminal终端和linux上终端光标的快捷键操作是一样的,都是来自Emacs这个神级的编辑器,由于我以前vim用的多,没怎么用 ...

  3. Ceph添加/删除Mon(ceph.conf)

    操作环境 ceph 0.87.7 Openstack liberty ubuntu 14.04 当前ceph配置文件如下 [global]fsid = c010eb34-ccc6-458d-9a03- ...

  4. js函数——倒计时模块和无缝滚动

    倒计时 效果: 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  5. MongoDB + Spark: 完整的大数据解决方案

    Spark介绍 按照官方的定义,Spark 是一个通用,快速,适用于大规模数据的处理引擎. 通用性:我们可以使用Spark SQL来执行常规分析, Spark Streaming 来流数据处理, 以及 ...

  6. 关于git的reset、checkout、revert

    https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting/file-level-operations 最 ...

  7. TreeGrid

    TreeGrid是树形表格,为了展示成树形,比数据表格主要增加了以下两点: 1.表格属性中设置 idField.treeField 两个属性:idField 表示用于区分上下级的主键,treeFiel ...

  8. 基本SQL命令 (1.SQL命令使用规则/2.库管理/3.表管理/4.表记录管理/5.更改库,库的默认字符集/6.连接数据库的过程/7.数据类型)

    1.SQL命令的使用规则       1.每条命令必须以 ; 结尾       2.SQL命令不区分字母大小写       3.使用 \c 终止SQL命令的执行 2.库的管理     1.库的基本操作 ...

  9. Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration

    在Apache的配置文件 httpd.conf 中开启  LoadModule headers_module modules/mod_headers.so  即可解决这个问题.

  10. Python基础:文件的基本操作

    # 打开文件(如果不存在则新建) 向其中写入 f = open('D:\\test.txt', 'w') f.write('hello world, i am here!') f.close() pr ...