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. 2018年11月25日ICPC焦作站参赛总结

    可能就这么退役了吧. 对这次ICPC还是比较有信心的,毕竟心态都放平和了. 路途很波折,热身赛还是赶上了. 等到了正赛的时候,开场看出了A题的签到,签到肯定是我来签的,11分钟签完了这道题之后,开始看 ...

  2. Mac下配置环境变量重启后不生效解决(.bash_profile vs .bashrc)(bash/zsh下不加载.bashrc问题解决)

    参考上一篇文章说明:http://www.cnblogs.com/EasonJim/p/6283094.html 得知加载顺序如下: /etc/profile /etc/paths ~/.bash_p ...

  3. 利用requestAnimationFrame和Tween算法实现兼容所有浏览器的运动动画,直接秒杀Css3动画

    以下贴出Tween的代码: /* * Tween.js * t: current time(当前时间): * b: beginning value(初始值): * c: change in value ...

  4. Angular 下的 function

    angular.lowercas 将指定的字符串转换为小写的 Usage(使用方法) angular.lowercase(string);   Arguments Param Type Details ...

  5. Linux学习7-文件操作

    标准I/O库(stdio)及其头文件stdio.h 为底层I/O系统调用提供了一个通用的接口. 在标准I/O库中,与底层文件描述符对应的是流(stream),它被实现为指向结构FILE的指针. 在启动 ...

  6. phantomjs 长图截屏

    var page = require('webpage').create(); var url = 'http://cardloan9.hateblo.jp/'; page.settings = { ...

  7. 详解PHP的执行原理和流程

    简介 先看看下面这个过程: • 我们从未手动开启过PHP的相关进程,它是随着Apache的启动而运行的: • PHP通过mod_php5.so模块和Apache相连(具体说来是SAPI,即服务器应用程 ...

  8. 【Unity_UWP】Unity 工程发布win10 UWP 时的本地文件读取 (下篇)

    Universal Windows Platform(UWP)是微软Windows10专用的通用应用平台,其目的在于在统一操作系统下控制所有智能电子设备. 自从Unity 5.2之后,配合VS 201 ...

  9. ajax最基础入门

    1.介绍 AJAX = 异步 JavaScript 和 XML. AJAX 是一种用于创建快速动态网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以在不重 ...

  10. Gearman In Action

    分布式任务系统是一个常见的需求,如果将 Gearman 作为 build block 来搭建这个系统的话,这样能够 make your life much easier. 首先看看 Gearman 是 ...