Codeforces Round #587 (Div. 3)

C. White Sheet

一道基础的几何题  给定三个矩形的左下角坐标和右上角坐标,第一块是白色矩形,第二第三都是黑色矩形,问白色矩形是否被黑色矩形完全覆盖。思路就是根据点判断分类讨论。

1、如果白色矩形的四个点没有全部被覆盖了   那么直接输出“NO”

2、如果白色矩形的四个点都被覆盖了,那么就再判断下黑色的矩形有没有交集

 1 #include <math.h>
 2 #include <stdio.h>
 3 #include <stdlib.h>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <string>
 7 #include <string.h>
 8 #include <vector>
 9 #include <map>
10 #include <stack>
11 #include <set>
12 #include <random>
13
14 #define LL long long
15
16 bool in(LL x1,LL y1,LL x2,LL y2,LL xx2,LL yy2) {
17     if (x1 >= x2 && x1 <= xx2 && y1>=y2 && y1<=yy2) {
18         return true;
19     }
20     return false;
21 }
22
23 int main() {
24     LL x1,y1,x2,y2,x3,y3;
25     LL xx1,yy1,xx2,yy2,xx3,yy3;
26     std::cin >> x1 >> y1 >> xx1 >> yy1;
27     std::cin >> x2 >> y2 >> xx2 >> yy2;
28     std::cin >> x3 >> y3 >> xx3 >> yy3;
29     if ((in(x1,y1,x2,y2,xx2,yy2) || in(x1,y1,x3,y3,xx3,yy3)) &&
30        (in(x1,yy1,x2,y2,xx2,yy2) || in(x1,yy1,x3,y3,xx3,yy3)) &&
31        (in(xx1,y1,x2,y2,xx2,yy2) || in(xx1,y1,x3,y3,xx3,yy3)) &&
32        (in(xx1,yy1,x2,y2,xx2,yy2) || in(xx1,yy1,x3,y3,xx3,yy3))) {
33         if (in(x2,y2,x3,y3,xx3,yy3) || in(x2,yy2,x3,y3,xx3,yy3) || in(xx2,y2,x3,y3,xx3,yy3) || in(xx2,yy2,x3,y3,xx3,yy3)
34             || in(x3,y3,x2,y2,xx2,yy2) || in(x3,yy3,x2,y2,xx2,yy2) || in(xx3,y3,x2,y2,xx2,yy2) || in(xx3,yy3,x2,y2,xx2,yy2)) {
35             std::cout << "NO" << std::endl;
36         }
37         else {
38             if ((in(x1,y1,x2,y2,xx2,yy2) && in(x1,yy1,x2,y2,xx2,yy2) && in(xx1,y1,x2,y2,xx2,yy2) && in(xx1,yy1,x2,y2,xx2,yy2)) ||
39                 (in(x1,y1,x3,y3,xx3,yy3) && in(x1,yy1,x3,y3,xx3,yy3) && in(xx1,y1,x3,y3,xx3,yy3) && in(xx1,yy1,x3,y3,xx3,yy3))) {
40                 std::cout << "NO" << std::endl;
41             }
42             else
43                 std::cout << "YES" << std::endl;
44         }
45     }
46     else {
47         std::cout << "YES" << std::endl;
48     }
49     return 0;
50 }

E2. Numerical Sequence (hard version)

这道题我觉得非常有意思。

如果我们取i从1开始 那么[10^(i-1),10^i) 里面每个sum[i] = i

 1 #include <math.h>
 2 #include <stdio.h>
 3 #include <stdlib.h>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <string>
 7 #include <string.h>
 8 #include <vector>
 9 #include <map>
10 #include <stack>
11 #include <set>
12 #include <random>
13
14 #define ll long long
15
16
17 inline ll get_sum ( ll x ) { //从1~区间长度x的前x项和
18
19     return x*(x+1)/2;
20 }
21
22 inline ll calc_1 ( ll x ) { // 获取ssum[x]
23
24     ll ans=0, i=1, j=1;
25     for ( ; j*10<=x; i++,j*=10 ) {  // 10*j == 10^i
26         // 10^i 之前的  +  10^i->x 之间的
27         ans += i*get_sum(j*9) + i*j*9*(x-j*10+1);  // i * [1,(10^i-10^(i-1))] == i * [1,(10*j-j)] == i * get_sum(j*9)
28                                                    // 一个而言需要增加:i*j*9 == (i * (10^i-1 - (10^(i-1)-1) ) ) == (i * (10 * j - j))
29                                                    // 一共有(x - 10^i + 1) == (x - 10 * j + 1)
30     }
31     // 加上后面部分的
32     return ans + i*get_sum(x-j+1);
33 }
34
35 inline ll calc_2 ( ll x ) { // 获取sum[x]
36
37     ll ans=0, i=1, j=1;
38     for ( ; j*10<=x; i++,j*=10 ) {
39         ans += i*j*9;
40     }
41     // 加上后面部分的
42     return ans + i*(x-j+1);
43 }
44
45 int main() {
46
47     ll q, k;
48     scanf("%lld", &q);
49
50     while (q--) {
51
52         scanf("%lld", &k);
53         ll l = 0, r = 1e9, res1, res2;
54
55         while ( l<=r ) { // 第一次二分确定k在哪个块里
56
57             ll mid = l+r >> 1;
58             if ( calc_1(mid) < k ) {
59                 l = mid + 1;
60                 res1 = mid;
61             }
62             else r = mid - 1;
63         }
64         k -= calc_1(res1);
65         l = 0, r = res1 + 1;
66         while ( l<=r ) { // 第二次二分确定k在哪个数里
67
68             ll mid = l+r >> 1;
69             if ( calc_2(mid) < k ) {
70                 l = mid + 1;
71                 res2 = mid;
72             }
73             else r = mid - 1;
74         }
75         k -= calc_2(res2 ++);
76
77         int a[30];
78         memset(a, 0, sizeof(a));
79         int i = 0;
80         while(res2) {
81             a[++i] = res2%10;
82             res2 /= 10;
83         }
84         printf("%d\n", a[i-k+1]);
85     }
86     return 0;
87 }

原文地址:https://www.cnblogs.com/-Ackerman/p/11695265.html

时间: 2024-08-03 04:50:16

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

Codeforces Round #587 (Div. 3) C - White Sheet

原文链接:https://www.cnblogs.com/xwl3109377858/p/11564279.html Codeforces Round #587 (Div. 3) C - White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you w

Codeforces Round #587 (Div. 3) B - Shooting

原文链接:https://www.cnblogs.com/xwl3109377858/p/11564214.html Codeforces Round #587 (Div. 3) B - Shooting Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a ta

Codeforces Round #587 (Div. 3) D - Swords

原文链接:https://www.cnblogs.com/xwl3109377858/p/11564317.html Codeforces Round #587 (Div. 3) D -Swords There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people

White Sheet (矩形面积模板) (Codeforces Round #587 (Div. 3) )

There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0,0)(0,0),

Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}

C. White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordina

Codeforces Round #587 (Div. 3) F Wi-Fi(线段树+dp)

题意:给定一个字符串s 现在让你用最小的花费 覆盖所有区间 思路:dp[i]表示前i个全覆盖以后的花费 如果是0 我们只能直接加上当前位置的权值 否则 我们可以区间询问一下最小值 然后更新 #include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int N = 2e5+7; typedef long long ll; const ll mod

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序列,如果我