CodeForces 279B Books】的更多相关文章

http://codeforces.com/problemset/problem/279/B 题意 :Valera 有很多的空闲时间,所以他决定看书,给出n本书,编号1到n,和看每本书需要的时间,他看书是随机的,然后是连续的,从第 i 本开始看,看完了会看第i+1本,然后是第i+2本,问他在时间 t 内最多能看多少本书. 思路 :一开始没看明白题意,以为把时间排序,从小开始往里加,后来才发现人家要求的是连续的.这个就是循环从头开始加,如果时间超了,就从第一本开始往外删. #include <io…
题意:给定n本书的阅读时间,然后你从第 i 本开始阅读,问你最多能看多少本书在给定时间内. 析:就是一个滑动窗口的水题. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream>…
好久没有写二分了 题意:有n本书 每本书有一个阅读时间ai 要在t时间内读最多的书 读书的顺序是连续的,如果无法读完一本书就不能开始 最开始觉得会是个dp,但是动规方程写不出来.想想会不会是二分呢,也写不出来 看了题解发现,输入的时候要做一个巧妙的处理 因为书是连续读的,如果ai存的是第1 到第i本书所用的时间总和的话, 那读[i,j]本书的时间就是ai-aj,这样就不需要循环算了啊! 于是固定一个起点 二分找终点 太久没写二分的结果就是 居然连二分的条件都不会了. #include<stdio…
Books CodeForces - 279B When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to…
B. Vanya and Books Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/problem/B Description Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books sh…
http://codeforces.com/contest/1066/problem/C You have got a shelf and want to put some books on it. You are given qq queries of three types: L idid — put a book having index idid on the shelf to the left from the leftmost existing book; R idid — put…
题目传送门 /* 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <vector> #include <string> #include <queue> #incl…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Vanya got an important task - he should enumerate books in the library and label each book with its number. Each of the n books should be assigne…
B. Vanya and Books time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vanya got an important task - he should enumerate books in the library and label each book with its number. Each of the n …
题目链接:http://codeforces.com/problemset/problem/1249/B2 思路:用并查集模拟链表,把关系串联起来,如果成环,则满足题意.之后再用并查集合并一个链,一个链代表 一个集合,一个集合有共同的祖先,一个集合答案相同,则输出答案时候只需要输出该元素属于哪一个集合,那个集合有几个元素 就可以了. #include <stdio.h> #include <iostream> using namespace std; ; int fa[N]; in…
题意:给出n本书,总的时间t,每本书的阅读时间a[i],必须按照顺序来阅读,问最多能够阅读多少本书 有点像紫书的第七章讲的那个滑动区间貌似 维护一个区间的消耗的时间小于等于t,然后维护一个区间的最大值 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<ma…
转换成前缀和, 预处理一下然后莫队. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ(x) ((int)x.size()) #de…
模拟题 开一个容器进行模拟即可,注意容器设置初始大小不然容易re.设置两个指针l,r.把容器当作桶,每一个桶都有一个编号表示位置,左边进入那么就是编号为l,右边一样.然后l--或者r++,l=r=0的初始值,第一个元素为0,然后同时l--,r++ 代码(cf上题解的算法) #include <bits/stdc++.h> using namespace std; main() { int n; cin>>n; deque<int> vec(300000); int l=…
The only difference between easy and hard versions is constraints. There are nn kids, each of them is reading a unique book. At the end of any day, the ii-th kid will give his book to the pipi-th kid (in case of i=pii=pi the kid will give his book to…
题意:有一组数,问子数组和最大不超过\(t\)的最多元素个数. 题解:用数组模拟队列,不断的往里面放,队列中的元素之和大于\(t\),就不断地从队头弹出直到满足条件,维护一个最大值即可. 代码: int n,t; int a[N]; int q[N]; int hh,tt=-1; int main() { //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); n=read(),t=read(); for(int i=1;i<=n;++i) a…
题意:有\(n\)本书,A和B都至少要从喜欢的书里面读\(k\)本书,如果一本书两人都喜欢的话,那么他们就可以一起读来节省时间,问最少多长时间两人都能够读完\(k\)本书. 题解:我们可以分\(3\)种情况来存,即: ​ 1.\(a=b=1\). 2.\(a=1,b=0\). 3.\(a=0,b=1\). 对于2和3来说,我们可以将他们排序,然后合并到一起,最后放到第1种情况中再排一次序,取前\(k\)个前缀和即可. 代码: int n,k; int t,x,y; int ans; vector…
题意:有一个一维的书架,\(L\)表示在最左端放一本书,\(R\)表示在最右端放一本书,\(?\)表示从左数或从右数,最少数多少次才能得到要找的书. 题解:我们开一个稍微大一点的数组,从它的中间开始模拟,\(L\)就--\(l\)放进去,\(R\)就++\(r\)放进去,然后每次更新某一本书的最新位置,因为后放的肯定离最左侧或最右侧最近,然后两端求差弄个最小值就行. 代码: int q; char c; int idx; int ans; int mp[2*N],now[2*N]; int ma…
 Phone Numbers Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 151B Description Winters are just damn freezing cold in Nvodsk! That's why a group of n friends prefers to take a taxi, ord…
Persistent Bookcase Problem Description: Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified. After reaching…
B. The Best Gift 题目连接: http://www.codeforces.com/contest/609/problem/B Description Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are n books on sale…
E. Exposition Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/6/E Description There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library d…
C. Median Smoothing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem/C Description A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that des…
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description you the conditions of this task. There are 3 pivots: A, B, C. Initially, n disks of different diameter are placed on the pivot A: the smallest dis…
B. The Best Gift  传送门:http://codeforces.com/problemset/problem/609/B Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are n books on sale from one of m…
CodeForces 816B Karen and Coffee(前缀和,大量查询) Description Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally ac…
Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/D Description Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive…
A. Vanya and Table   Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose n re…
http://codeforces.com/contest/1073 A. Diverse Substring #include <bits/stdc++.h> using namespace std; #define ll long long #define minv 1e-6 #define inf 1e9 #define pi 3.1415926536 #define nl 2.7182818284 ; ; char s[maxn]; int main() { int n,i; scan…
D. Persistent Bookcase 题目连接: http://www.codeforces.com/contest/707/problem/D Description Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and a…
Codeforces Round #515 (Div. 3) #include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<queue> #include<vector> #incl…