Codeforces Round #515 (Div. 3)
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> #include<map> #define lson i<<1 #define rson i<<1|1 #define LS l,mid,lson #define RS mid+1,r,rson #define mem(a,x) memset(a,x,sizeof(a)) #define gcd(a,b) __gcd(a,b) #define ll long long #define ull unsigned long long #define lowbit(x) (x&-x) #define pb(x) push_back(x) #define enld endl #define mian main #define itn int #define prinft printf #pragma GCC optimize(2) //#pragma comment(linker, "/STACK:102400000,102400000") const double PI = acos (-1.0); const int INF = 0x3f3f3f3f; ; ; ; ; using namespace std; /* 4 10 2 3 7 100 51 51 51 1234 1 100 199 1000000000 1 1 1000000000 */ int n,L,v,l,r; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); while(cin>>n) { while(n--) { cin>>L>>v>>l>>r; cout<<L/v-(r/v-(l-)/v)<<endl; } } }
A - Vova and Train
分区间讨论,不断更新右极值,注意边界相切的情况(1,2)(3,4)
#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<queue> #include<vector> #include<map> #define lson i<<1 #define rson i<<1|1 #define LS l,mid,lson #define RS mid+1,r,rson #define mem(a,x) memset(a,x,sizeof(a)) #define gcd(a,b) __gcd(a,b) #define ll long long #define ull unsigned long long #define lowbit(x) (x&-x) #define pb(x) push_back(x) #define enld endl #define mian main #define itn int #define prinft printf #pragma GCC optimize(2) //#pragma comment(linker, "/STACK:102400000,102400000") const double PI = acos (-1.0); const int INF = 0x3f3f3f3f; ; ; ; ; using namespace std; /* 6 2 0 1 1 0 0 1 */ int n,r,a[MAXN]; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); while(cin>>n>>r) { mem(a,); ; ; ; i<=n; ++i) { cin>>temp; if(temp) { a[++cnt]=i; } } temp=; ; ; -)<n||a[]-r+>||a[cnt]+r-<n) cout<<-<<endl; else { ; i<=cnt; ++i) { >temp+) { //cout<<temp<<' '<<a[i]-r+1<<endl; cout<<-<<endl; flag=; break; } if(temp>=n) { //k++; break; } <=temp+&&a[i+]-r+>temp+)||a[i]+r->=n) { //cout<<i<<endl; k++; temp=a[i]+r-; } //cout<<temp<<' '; } if(!flag) cout<<k<<endl; } } }
B - Heaters
#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<queue> #include<vector> #include<map> #define lson i<<1 #define rson i<<1|1 #define LS l,mid,lson #define RS mid+1,r,rson #define mem(a,x) memset(a,x,sizeof(a)) #define gcd(a,b) __gcd(a,b) #define ll long long #define ull unsigned long long #define lowbit(x) (x&-x) #define pb(x) push_back(x) #define enld endl #define mian main #define itn int #define prinft printf #pragma GCC optimize(2) //#pragma comment(linker, "/STACK:102400000,102400000") const double PI = acos (-1.0); const int INF = 0x3f3f3f3f; ; ; ; ; using namespace std; /* 8 L 1 R 2 R 3 ? 2 L 4 ? 1 L 5 ? 1 */ int n; char c; int ind; int a[MAXN]; int main() { //std::ios::sync_with_stdio(false); //cin.tie(NULL); while(cin>>n) { ,r=; mem(a,); while(n--) { cin>>c>>ind; if(c=='L') { a[ind]=l--; } else if(c=='R') { a[ind]=r++; } else { //cout<<a[ind]<<' '<<a[l+1]<<' '<<l+1<<endl; cout<<min(a[ind]-(l+),r--a[ind])<<endl; } } } }
C - Books Queries
逆推+二分
#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<queue> #include<vector> #include<map> #define lson i<<1 #define rson i<<1|1 #define LS l,mid,lson #define RS mid+1,r,rson #define mem(a,x) memset(a,x,sizeof(a)) #define gcd(a,b) __gcd(a,b) #define ll long long #define ull unsigned long long #define lowbit(x) (x&-x) #define pb(x) push_back(x) #define enld endl #define mian main #define itn int #define prinft printf #pragma GCC optimize(2) //#pragma comment(linker, "/STACK:102400000,102400000") const double PI = acos (-1.0); const int INF = 0x3f3f3f3f; ; ; ; ; using namespace std; int n,m,k; int a[MAXN]; int b[MAXN]; bool check(int x) { mem(b,); ; ; i<=x; ++i) { ; for(int j=temp; j<=m; ++j) { if(b[j]+a[i]<=k) { flag=; b[j]+=a[i]; temp=j; break; } } if(!flag) return false; } return true; } int main() { //std::ios::sync_with_stdio(false); //cin.tie(NULL); while(cin>>n>>m>>k) { mem(a,),mem(b,); ; i--) cin>>a[i]; ,r=n+,mid,cnt=; while(cnt--) { mid=(l+r)/; if (check(mid)) l=mid; else r=mid; } cout<<mid<<endl; } /* while(cin>>n>>m>>k) { for(int i=n; i>=1; i--) cin>>a[i]; int x; cin>>x; cout<<check(x)<<endl; } */ }
D - Boxes Packing
Codeforces Round #515 (Div. 3)的更多相关文章
- Codeforces Round #515 (Div. 3) 解题报告(A~E)
题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...
- Codeforces Round #515 (Div. 3) B. Heaters【 贪心 区间合并细节 】
任意门:http://codeforces.com/contest/1066/problem/B B. Heaters time limit per test 1 second memory limi ...
- Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum
E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个 ...
- CodeForces Round #515 Div.3 D. Boxes Packing
http://codeforces.com/contest/1066/problem/D Maksim has nn objects and mm boxes, each box has size e ...
- CodeForces Round #515 Div.3 C. Books Queries
http://codeforces.com/contest/1066/problem/C You have got a shelf and want to put some books on it. ...
- CodeForces Round #515 Div.3 A. Vova and Train
http://codeforces.com/contest/1066/problem/A Vova plans to go to the conference by train. Initially, ...
- CodeForces Round #515 Div.3 B. Heaters
http://codeforces.com/contest/1066/problem/B Vova's house is an array consisting of nn elements (yea ...
- CodeForces Round #515 DIv.3 F. Yet another 2D Walking
http://codeforces.com/contest/1066/problem/F Maksim walks on a Cartesian plane. Initially, he stands ...
- B. Heaters ( Codeforces Round #515 (Div. 3) )
题解:对于每个点 i 来说,从 j = i + r - 1 开始往前找,如果找到一个 a [ j ] 是 1 ,那么就把它选上,但是我们需要判断交界处,也就是如果前面选的那个可以让这个点变温暖,就不用 ...
随机推荐
- 小议 开源中国 I LOVE YOU js代码
今天在开源中国看到一篇神作<I LOVE YOU js代码>是17号的文章了,也许你已经看过了. 文章非常有意思,由 5 个 "爱心" 组成的一段js代码,能正常执行, ...
- Android手机间无线互传功能探索及实现
年前研究了一下Android如何实现无线互传的功能,写了个小demo,最近无事,遂整理一下,与各位共享.前期调研发现,Android想要实现无线互传有以下几种技术:1,Bluetooth通行已久,简单 ...
- nagios报警延迟的解决--flapping state
这个问题是在测试中发现的.因为要在服务器上布置nagios用来监控oracle,可是发现手动shutdown数据库后能够很快报警,但是再startup后就不是很及时,有时会延迟很久.经过研究发现了这个 ...
- nginx tomcat 自动部署python脚本【转】
#!/usr/bin/env python #--coding:utf8-- import sys,subprocess,os,datetime,paramiko,re local_path='/ho ...
- Parameters.Add和Parameters.AddWithValue
因为vs2013没有更新update 5所以Parameters.Add可以用Parameters.AddWithValue赋值无效 更新后可以. Parameters.AddWithValue的底层 ...
- Kotlin 语言下设计模式的不同实现
偶然在 Github 上看到 dbacinski 写的 Kotlin 语言下设计模式的不同实现(这里的不同是相对于 Java 语言的),有些实现非常好,但是有些实现的例子不是很赞同.所以自己写了 Ko ...
- oracle数据库_实例_用户_表空间之间的关系
基础概念:Oracle数据库.实例.用户.表空间.表之间的关系 数据库:Oracle数据库是数据的物理存储.这就包括(数据文件ORA或者DBF.控制文件.联机日志.参数文件).其实Oracle数据库的 ...
- 转:Vue-cli proxyTable 解决开发环境的跨域问题
转:http://www.jianshu.com/p/95b2caf7e0da 和后端联调时总是会面对恼人的跨域问题,最近基于Vue开发项目时也遇到了这个问题,两边各自想了一堆办法,查了一堆资料,加了 ...
- (三)发布Dubbo服务
我们现在来学习下发布Dubbo服务,主要参考dubbo开发包里的demo源码:由浅入深的讲解下这个小demo: github地址:https://github.com/apache/incubator ...
- InnoDB Lock浅谈
数据库使用锁是为了支持更好的并发,提供数据的完整性和一致性.InnoDB是一个支持行锁的存储引擎,锁的类型有:共享锁(S).排他锁(X).意向共享(IS).意向排他(IX).为了提供更好的并发,Inn ...