题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?

pid=17121

2014-04-25 22:59:49

不和谐的长难句1

Time Limit: 8000ms
Case Time Limit: 2000ms
Memory Limit: 65536KB
64-bit integer IO format: %lld      Java class name: Main

pid=17120" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="margin:0px 0.1em 0px -1px; padding:0px; text-decoration:none; font-family:'Trebuchet MS',Helvetica,Arial,sans-serif; font-size:1.1em; border:1px solid rgb(204,204,204); background-color:rgb(238,238,238); font-weight:bold; color:rgb(68,68,68); display:inline-block; position:relative; zoom:1; overflow:visible">Prev Submit 

showpid=17121" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="margin:0px 0.1em 0px -1px; padding:0px; text-decoration:none; font-family:'Trebuchet MS',Helvetica,Arial,sans-serif; font-size:1.1em; border:1px solid rgb(204,204,204); background-color:rgb(238,238,238); font-weight:bold; color:rgb(68,68,68); display:inline-block; position:relative; zoom:1; overflow:visible">Status 

pid=17121" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="margin:0px 0.1em 0px -1px; padding:0px; text-decoration:none; font-family:'Trebuchet MS',Helvetica,Arial,sans-serif; font-size:1.1em; border:1px solid rgb(204,204,204); background-color:rgb(238,238,238); font-weight:bold; color:rgb(68,68,68); display:inline-block; position:relative; zoom:1; overflow:visible">Statistics Discuss 

pid=17122" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="margin:0px 0.1em 0px -1px; padding:0px; text-decoration:none; font-family:'Trebuchet MS',Helvetica,Arial,sans-serif; font-size:1.1em; border:1px solid rgb(204,204,204); background-color:rgb(238,238,238); font-weight:bold; color:rgb(68,68,68); display:inline-block; position:relative; zoom:1; overflow:visible">Next

Font Size: 
+
 
-
Type:  
None Graph Theory 
    2-SAT     Articulation/Bridge/Biconnected Component
     Cycles/Topological Sorting/Strongly Connected Component
     Shortest Path 
        Bellman Ford         Dijkstra/Floyd Warshall
     Euler Trail/Circuit
     Heavy-Light Decomposition
     Minimum Spanning Tree
     Stable Marriage Problem
     Trees 
    Directed Minimum Spanning Tree 
    Flow/Matching         Graph Matching
             Bipartite Matching
             Hopcroft–Karp Bipartite Matching
             Weighted Bipartite Matching/Hungarian Algorithm
         Flow 
            Max Flow/Min Cut 
            Min Cost Max Flow 
DFS-like     Backtracking with Pruning/Branch and Bound
     Basic Recursion 
    IDA* Search     Parsing/Grammar
     Breadth First Search/Depth First Search
     Advanced Search Techniques
         Binary Search/Bisection
         Ternary Search
 Geometry 
    Basic Geometry     Computational Geometry
     Convex Hull 
    Pick's Theorem Game Theory
     Green Hackenbush/Colon Principle/Fusion Principle
     Nim 
    Sprague-Grundy Number 
Matrix     Gaussian Elimination
     Matrix Exponentiation
 Data Structures 
    Basic Data Structures 
    Binary Indexed Tree 
    Binary Search Tree 
    Hashing     Orthogonal Range Search
     Range Minimum Query/Lowest Common Ancestor
     Segment Tree/Interval Tree
     Trie Tree 
    Sorting     Disjoint Set
 String 
    Aho Corasick     Knuth-Morris-Pratt
     Suffix Array/Suffix Tree
 Math 
    Basic Math     Big Integer Arithmetic
     Number Theory 
        Chinese Remainder Theorem 
        Extended Euclid 
        Inclusion/Exclusion 
        Modular Arithmetic 
    Combinatorics         Group Theory/Burnside's lemma
         Counting 
    Probability/Expected Value 
Others     Tricky 
    Hardest     Unusual
     Brute Force 
    Implementation     Constructive Algorithms
     Two Pointer 
    Bitmask     Beginner
     Discrete Logarithm/Shank's Baby-step Giant-step Algorithm
     Greedy 
    Divide and Conquer 
Dynamic Programming

Tag it!

某L近期很苦逼地在看一本叫做《鸡阿姨&鸡玛特 阅读难句教程》的书,这本书的主要内容就是解说一堆奇怪的难懂的无比冗长同一时候又让人看了想睡觉的“长难句”,每一个句子中都有无数不认识的单词外加倒装、省略、插入语、复杂修饰、和固定搭配。然后还总是让人看到晕头转向都看不到一个句号。

但更让人纠结的是,在这么BT的前提下,竟然还有些句子由于排版原因被分在了两页(即前一页的最后几行和后一页的前几行),这让某L非常恼火,于是他開始观察这本书的排版方式【这关注点真偏— —||】,他发现。这本书的结构事实上非常easy。书中共同拥有N(N<=10^6)个小段,每段包含一个带有编号长难句和其相应的解说。每一个长难句都占5行(包含其编号),而编号为i的长难句相应的解说占a[i]行。

排版顺序则是依照长难句的编号由小到大。每一个长难句之后紧接着就是其相应的解说。然后再紧跟着下一个长难句和其相应的解说……由于书中每一页最多仅仅能排30行内容。所以导致了上述悲剧的发生。

为了解决问题。某L想在每一个小段中间加上一些空行(当然也能够不加)。使得全部的长难句都在同一页内。那么他最少须要加多少个空行呢=,=

Input

一个整数N,表示一共同拥有N的小段

接下来N行,每行两个数m、a[m]。表示编号为m的长难句相应的解说占a[m]行。

0<N<=10^6

1<=m<=N,而且不会反复

a[m]为int型正整数。

Output

一个整数P。表示最少须要加入的空行的数目

Sample Input

2
1 24
2 10

Sample Output

1

Hint

输入量巨大。请使用scanf,使用cin的话可能TLE。

也是水题一道。。。

只是比赛的时候没想出来,后来才AC的。

。。设m为上次没放完的那一部分则 m=(m+5+a[i])%30,则30-m即为这次应该加上的行数,只是这样的算法会把最后一页的也加上,所以要扣掉

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int a[1000003];
int main()
{
int n,m,sum;
cin>>n;
for(int i=1;i<=n;i++)
{
scanf("%d",&m);
scanf("%d",&a[m]);
}
sum=0;
m=0;
for(int i=1;i<=n;i++)
{
m=(m+5+a[i])%30;
if(m>25&&m<30)
{
sum+=30-m;
if(i!=n)
m=0;
}
}
if(m>25&&m<30)
sum-=30-m;
cout<<sum<<endl;
return 0;
}

第12届北师大校赛热身赛第二场 A.不和谐的长难句1的更多相关文章

  1. 第12届北师大校赛热身赛第二场 C. 组合数

    题目链接:http://www.bnuoj.com/bnuoj/contest_show.php?cid=3570#problem/43573 C. 组合数 Time Limit: 1000ms Ca ...

  2. 第12届北师大校赛热身赛第二场 B起床的烦恼

    题目链接:http://www.bnuoj.com/bnuoj/contest_show.php? cid=3570#problem/43572 题目大意: Nono从一開始数数,他每数一个数时会计算 ...

  3. 2019牛客暑假多校赛(第二场) F和H(单调栈)

    F-Partition problem https://ac.nowcoder.com/acm/contest/882/F 题意:输入一个数n,代表总共有2n个人,然后每个人对所有人有个贡献值,然后问 ...

  4. 【杂题总汇】HDU多校赛第十场 Videos

    [HDU2018多校赛第十场]Videos 最后一场比赛也结束了…… +HDU传送门+ ◇ 题目 <简要翻译> 有n个人以及m部电影,每个人都有一个快乐值.每场电影都有它的开始.结束时间和 ...

  5. 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?

    牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...

  6. NOIP2018 全国热身赛 第二场 (不开放)

    NOIP2018 全国热身赛 第二场 (不开放) 题目链接:http://noi.ac/contest/26/problem/60 一道蛮有趣的题目. 然后比赛傻逼了. 即将做出来的时候去做别的题了. ...

  7. 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)

    2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...

  8. 2018牛客网暑假ACM多校训练赛(第二场)E tree 动态规划

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round2-E.html 题目传送门 - 2018牛客多校赛第二场 E ...

  9. 牛客网多校赛第9场 E-Music Game【概率期望】【逆元】

    链接:https://www.nowcoder.com/acm/contest/147/E 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...

随机推荐

  1. 小学生之Java中迭代器实现的原理

    一. 引言 迭代这个名词对于熟悉Java的人来说绝对不陌生.我们常常使用JDK提供的迭代接口进行java collection的遍历: Iterator it = list.iterator();wh ...

  2. python的exec、eval详解

    exec exec语句用来执行储存在字符串或文件中的Python语句.例如,我们可以在运行时生成一个包含Python代码的字符串,然后使用exec语句执行这些语句.下面是一个简单的例子. exec ' ...

  3. ajax调用action后返回list给list.jsp,显示为xml文档

    struts2中使用的是map来保存数据的,所以这里绑定的值是key和value1 <?xml version="1.0" encoding="UTF-8" ...

  4. 以下是jQuery和JavaScript实现相同操作的等价代码。

    选择元素  Javascript代码 1.// jQuery   2.var els = $('.el');   3.  4.// 原生方法   5.var els = document.queryS ...

  5. linux内核学习之进程管理------task_struct结构体

    struct task_struct { volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */ struct t ...

  6. 高放的python学习笔记之基本语法

    python与c++的不同之处 python的语句块不是用{}括起来的而是冒号后面跟一些与比当前语句多一的tab缩进的语句. 1.定义变量 python的变量类型不需要人为指出,会根据赋值的类型决定此 ...

  7. Python操作excel(xlrd和xlwt)

    Python操作excel表格有很多支持的库,例如:xlrd.xlwt.openpyxl.win32com,下面介绍使用xlrd.xlwt和xlutils模块这三个库不需要其他的支持,在任何操作系统上 ...

  8. c语言输入一行未知个数数字存入数组

    一直有个疑问输入一行数字存入数组时若不知道数字的个数怎么办,最容易想到的办法就是接收字符然后转化为数字,但这样太过麻烦. 今天上网查了下,说可以用ungetc()函数将字符送回输入流,在这里总结归纳一 ...

  9. stdarg.h详解

    读Linux内核中的vsprintf函数的时候遇到了C语言的可变参数调用,查了挺多资料还是这篇比较详细,而且自己验证了下,确实如此 (一)写一个简单的可变参数的C函数  下面我们来探讨如何写一个简单的 ...

  10. PHP浮点数的一个常见问题的解答

    作者: Laruence 本文地址: http://www.laruence.com/2013/03/26/2884.html 转载请注明出处 关于PHP的浮点数, 我之前写过一篇文章: 关于PHP浮 ...