题意:给你 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. 【UVA】12100 Printer Queue(STL队列&优先队列)

    题目 题目     分析 练习STL     代码 #include <bits/stdc++.h> using namespace std; int main() { int t; sc ...

  2. Linux更换jdk版本的一些问题

    111111111111111111111111111111111111111111111111111111111111111111111111 在服务器上更新了新的 jdk,也在 /etc/prof ...

  3. cocostudio使用plist创建序列帧动画图片名称序列错乱的问题

    cocostudio 版本v2.2.9 用texturePacker将动画帧打包成一个plist和一张png,将plist拖入cocostudio中的资源栏中. 如图所示,plist里面的图片顺序是乱 ...

  4. 如何查找EI 及SCI 索引

    1.EI https://www.engineeringvillage.com/search/quick.url 搜题目,然后点击搜索,然后点击细节(detailed) Accession numbe ...

  5. vue表单验证--veevalidate使用教程

    vue表单验证----vee-validate使用教程 官网:https://baianat.github.io/vee-validate/ 一.安装 npm install vee-validate ...

  6. ARP数据包伪造

      一台网络中的计算机,其传递到网络中的数据包的内容是完全由其软硬件逻辑决定的,软件可以操控硬件,硬件亦是一种特殊的软件,所以,接收者只根据数据包的内容,绝不可能判定此数据包的真正来源,一切都是可以伪 ...

  7. **字符串格式化:%和.format

    字符串格式化:%和.format .format在许多方面看起来更便利.对于%最烦人的是它无法同时传递一个变量和元组.你可能会想下面的代码不会有什么问题: "hi there %s" ...

  8. Dbvisualizer设置SQL语句自动提示

    Dbvisualizer默认不自动提示SQL语句的命令及查询的表,虽然可以通过Ctrl+/快捷键进行手动调用出提示信息,用习惯了PLSQL Developer难免有些不适应. 设置自动提示方法: 点击 ...

  9. Page directive: illegal to have multiple occurrences of contentType with different values

    org.apache.jasper.JasperException: /commons/meta.jsp(1,1) PWC5988: Page directive: illegal to have m ...

  10. SPI子系统分析之三:驱动模块

    内核版本:3.9.5 SPI核心层(平台无关) SPI子系统初始化的第一步就是将SPI总线注册进内核,并且在/sys下创建一个spi_master的类,以后注册的从设备都将挂接在该总线下. 下列函数位 ...