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)的更多相关文章

  1. Codeforces Round #515 (Div. 3) 解题报告(A~E)

    题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...

  2. Codeforces Round #515 (Div. 3) B. Heaters【 贪心 区间合并细节 】

    任意门:http://codeforces.com/contest/1066/problem/B B. Heaters time limit per test 1 second memory limi ...

  3. Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum

    E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个 ...

  4. 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 ...

  5. 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. ...

  6. 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, ...

  7. 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 ...

  8. 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 ...

  9. B. Heaters ( Codeforces Round #515 (Div. 3) )

    题解:对于每个点 i 来说,从 j = i + r - 1 开始往前找,如果找到一个 a [ j ] 是 1 ,那么就把它选上,但是我们需要判断交界处,也就是如果前面选的那个可以让这个点变温暖,就不用 ...

随机推荐

  1. (一)Git时间--初识版本控制工具

    //配置一下你的身份 git config --global use.name "Douzi" git config --global use.email "jdouzi ...

  2. Liberty Mutual Property Inspection, Winner's Interview: Qingchen Wang

    Liberty Mutual Property Inspection, Winner's Interview: Qingchen Wang The hugely popular Liberty Mut ...

  3. php设计模式之注册树模式

    什么是注册树模式?[全局共享和交换对象] 注册树模式当然也叫注册模式,注册器模式.注册树模式通过将对象实例注册到一棵全局的对象树上,需要的时候从对象树上采摘的模式设计方法.   这让我想起了小时候买糖 ...

  4. 线性筛的同时得到欧拉函数 (KuangBin板子)

    线性筛的思想:每个被筛的数是通过它最小的质因子所筛去的. 这种思想保证了每个数只会被筛一次,从而达到线性.并且,这个思想实现起来非常巧妙(见代码注释)! 因为线性筛的操作中用到了倍数的关系去实现,因此 ...

  5. requests(一): 发送一个json格式的post请求

    今天给一位同学解决post发送数据格式为json格式的请求,顺便确认一下问题归属. 背景: 用postman工具发送一个数据格式为json的请求,得到了服务器的响应. 用python的requests ...

  6. Expression Tree Build

    The structure of Expression Tree is a binary tree to evaluate certain expressions.All leaves of the ...

  7. Linux中断(interrupt)子系统之五:软件中断(softIRQ)

    转自:http://blog.csdn.net/droidphone/article/details/7518428 软件中断(softIRQ)是内核提供的一种延迟执行机制,它完全由软件触发,虽然说是 ...

  8. Jenkins 安装及使用

    jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作. 可以用它做网站代码提交,更新. 1,安装 首先确保目标机器上装有 java jdk 版本最好在 1.6 以上,小编使用的是 ...

  9. 公共语言运行库(CLR)开发系列课程(1):Pinvoke 简介 学习笔记

    前言 让拖管代码对象和非托管对象协同工作的过程称为互用性(Interoperability),通常简称为 Interop. P/Invoke在托管代码与非托管代码交互式时产生一个事务(Transiti ...

  10. Window8.1下oracle数据库报:ora-12170 操作超时

    PLSQL 链接本机:oracle11g 服务名:orcl   一直链接不上,等了大概3分钟, 提示:ora-12170操作超时: 重启了数据库 问题还是无法解决;上网搜了一下,发现报ora-1217 ...