Codeforces Round #515 (Div. 3)

Codeforces Round #515 (Div. 3)

 1 #include<bits/stdc++.h>
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cstdlib>
 5 #include<cstring>
 6 #include<cmath>
 7 #include<algorithm>
 8 #include<queue>
 9 #include<vector>
10 #include<map>
11 #define lson i<<1
12 #define rson i<<1|1
13 #define LS l,mid,lson
14 #define RS mid+1,r,rson
15 #define mem(a,x) memset(a,x,sizeof(a))
16 #define gcd(a,b) __gcd(a,b)
17 #define ll long long
18 #define ull unsigned long long
19 #define lowbit(x) (x&-x)
20 #define pb(x) push_back(x)
21 #define enld endl
22 #define mian main
23 #define itn int
24 #define prinft printf
25 #pragma GCC optimize(2)
26 //#pragma comment(linker, "/STACK:102400000,102400000")
27
28 const double PI = acos (-1.0);
29 const int INF = 0x3f3f3f3f;
30 const int EXP = 1e-8;
31 const int N = 1e5 + 5;
32 const int MOD = 1e9 + 7;
33 const int MAXN = 505;
34
35 using namespace std;
36
37 /*
38 4
39 10 2 3 7
40 100 51 51 51
41 1234 1 100 199
42 1000000000 1 1 1000000000
43 */
44 int n,L,v,l,r;
45 int main() {
46     std::ios::sync_with_stdio(false);
47     cin.tie(NULL);
48
49     while(cin>>n) {
50         while(n--) {
51             cin>>L>>v>>l>>r;
52             cout<<L/v-(r/v-(l-1)/v)<<endl;
53         }
54     }
55 }

A - Vova and Train

 1 #include<bits/stdc++.h>
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cstdlib>
 5 #include<cstring>
 6 #include<cmath>
 7 #include<algorithm>
 8 #include<queue>
 9 #include<vector>
10 #include<map>
11 #define lson i<<1
12 #define rson i<<1|1
13 #define LS l,mid,lson
14 #define RS mid+1,r,rson
15 #define mem(a,x) memset(a,x,sizeof(a))
16 #define gcd(a,b) __gcd(a,b)
17 #define ll long long
18 #define ull unsigned long long
19 #define lowbit(x) (x&-x)
20 #define pb(x) push_back(x)
21 #define enld endl
22 #define mian main
23 #define itn int
24 #define prinft printf
25 #pragma GCC optimize(2)
26 //#pragma comment(linker, "/STACK:102400000,102400000")
27
28 const double PI = acos (-1.0);
29 const int INF = 0x3f3f3f3f;
30 const int EXP = 1e-8;
31 const int N = 1e5 + 5;
32 const int MOD = 1e9 + 7;
33 const int MAXN = 2e5+5;
34
35 using namespace std;
36
37 /*
38 8
39 L 1
40 R 2
41 R 3
42 ? 2
43 L 4
44 ? 1
45 L 5
46 ? 1
47 */
48 int n;
49 char c;
50 int ind;
51 int a[MAXN];
52 int main() {
53     //std::ios::sync_with_stdio(false);
54     //cin.tie(NULL);
55
56     while(cin>>n) {
57         int l=0,r=1;
58         mem(a,0);
59         while(n--) {
60             cin>>c>>ind;
61             if(c==‘L‘) {
62                 a[ind]=l--;
63             } else if(c==‘R‘) {
64                 a[ind]=r++;
65             } else {
66                 //cout<<a[ind]<<‘ ‘<<a[l+1]<<‘ ‘<<l+1<<endl;
67                 cout<<min(a[ind]-(l+1),r-1-a[ind])<<endl;
68             }
69         }
70
71     }
72 }

C - Books Queries

原文地址:https://www.cnblogs.com/chunibyo/p/9834707.html

时间: 2024-10-29 16:32:59

Codeforces Round #515 (Div. 3)的相关文章

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

题目链接:http://codeforces.com/contest/1066 A题: 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在路上从l到r处停着别的火车,它挡着Vova的视线使他看不到灯笼.给定L,v,l,r求Vova能看到的灯笼数. 分析:从1到x上所有的灯笼数量为x/v个.则路上所有的灯笼数为L/v个,被挡住的则为 r/v - (l-1)/v 个,相减即为答案. #include<iostream> #include<cstdio> #inc

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd

Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除

Codeforces Round #339 (Div. 2) B. Gena&#39;s Code

B. Gena's Code It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, f

Codeforces Round #315 (Div. 1)

A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un

DP Codeforces Round #303 (Div. 2) C. Woodcutters

题目传送门 1 /* 2 题意:每棵树给出坐标和高度,可以往左右倒,也可以不倒 3 问最多能砍到多少棵树 4 DP:dp[i][0/1/2] 表示到了第i棵树时,它倒左或右或不动能倒多少棵树 5 分情况讨论,若符合就取最大值更新,线性dp,自己做出来了:) 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 #include <cstring> 10 #include <cmath> 11 #include &