您的位置:首页 > 其它

第12届北师大校赛热身赛第二场 A.不和谐的长难句1

2014-04-25 23:00 477 查看
题目链接: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

Prev Submit Status Statistics Discuss 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非常恼火,于是他开始观察这本书的排版方式【这关注点真偏— —||】,他发现,这本书的结构其实很简单,书中共有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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: