A. Minimum Integer

  1. 如果\(d < l\),则\(d\)满足条件
  2. 否则,输出\(d * (r / d + 1)\)即可。
#include <cstdio>
#include <iostream>
using namespace std;
int main(){
int T; scanf("%d", &T);
while(T--){
int l, r, d; scanf("%d%d%d", &l, &r, &d);
if(d < l) printf("%d\n", d);
else printf("%d\n", d * (r / d + 1));
}
return 0;
}

B. Accordion

找到头尾的\([:\)和\(:]\),然后统计中间有几个\(|\)即可。

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int N = 500010;
int n;
char s[N];
int main(){
scanf("%s", s + 1);
n = strlen(s + 1);
int l = 1, r = n, cnt = 0;
while(l <= n && s[l] != '[') l++;
while(r && s[r] != ']') r--;
while(l <= n && s[l] != ':') l++;
while(r && s[r] != ':') r--;
if(l >= r) puts("-1");
else{
for(int i = l; i <= r; i++)
if(s[i] == '|') cnt++;
printf("%d\n", 4 + cnt);
} return 0;
}

C. Division and Union

发现可以竖着一条线将所有线分开成两部分,则两边任意选都可以。那么我们就可以找到这个条线。把线段按左端点排序,每次如果有交集就合并,没有交集,我们就找到了一个"断点"。

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
const int N = 100010;
int n, l[N], r[N];
PII a[N];
int main(){
int T; scanf("%d", &T);
while(T--){
scanf("%d", &n);
for(int i = 1; i <= n; i++){
scanf("%d%d", l + i, r + i);
a[i].first = l[i];
a[i].second = r[i];
}
sort(a + 1, a + 1 + n);
int rr = a[1].second, loc = 0;
for(int i = 2; i <= n; i++){
if(a[i].first <= rr)
rr = max(rr, a[i].second);
else { loc = rr; break; }
}
if(!loc) printf("-1");
else for(int i = 1; i <= n; i++)
if(r[i] <= rr) printf("1 ");
else printf("2 ");
puts("");
}
return 0;
}

D. GCD Counting

树形\(dp\),\(100000\)以内的每个数因子不超过\(256\)个(最多\(2 ^ 3 * 3 * 5 * 7 * 9 * 13 * 19 > 100000\))

首先把每个读入的权值质因数分解,两个数必须有质因子\(gcd\)才不会$ = 1\(。存在一条边\)(u, v)\(,若\)u\(和\)v$之间有相同的质因子则可以合并,但注意下一次合并必须也有这个质因子...

所以设计\(f[i][j]\)为\(i\)个点为根节点,以第\(j\)个质因子为保障的最大长度。更新显然,如果遇到新的更新,答案可以更新,现在的 + 可以更新的。

所以... 虽然看似会炸掉,但是还是卡过了...

#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
const int N = 200010;
int n, a[N], ans = 1;
vector<int> G[N], p[N], f[N];
bool success = true;
void dfs(int u, int last){
for(int i = 0; i < G[u].size(); i++){
int v = G[u][i];
if(v == last) continue;
dfs(v, u);
for(int j = 0; j < p[u].size(); j++){
for(int k = 0; k < p[v].size(); k++){
if(p[u][j] == p[v][k]){
ans = max(ans, f[u][j] + f[v][k]);
f[u][j] = max(f[u][j], f[v][k] + 1);
}
}
}
}
}
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", a + i);
if(a[i] != 1) success = false;
int x = a[i];
for(int j = 2; j * j <= a[i]; j++){
if(x % j == 0){
p[i].push_back(j);
f[i].push_back(1);
while(x % j == 0) x /= j;
}
}
if(x > 1) p[i].push_back(x), f[i].push_back(1); }
for(int i = 1; i < n; i++){
int u, v; scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
if(success) puts("0");
else{
dfs(1, 0);
printf("%d", ans);
}
return 0;
}

E. Polycarp's New Job

两者都符合交换律,所以我们交换使得:

让\(x <= y\),\(h <= w\)。

维护\(x\)和\(y\)的最大值,\(max\_x\)和\(max\_y\)

检查$max_x <= h $ \(\&\&\) \(max\_y <= w\)即可。

显然,如果符合$max_y <= h $ \(\&\&\) \(max\_x <= w\),那么前者显然必然成立:

如果不符合,前者也有可能成立。

#include <cstdio>
#include <iostream>
using namespace std;
const int N = 500010;
int n, a = 0, b = 0;
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++){
char ch; cin >> ch;
if(ch == '+'){
int x, y; scanf("%d%d", &x, &y);
if(x > y) swap(x, y);
a = max(a, x);
b = max(b, y);
}else{
int h, w; scanf("%d%d", &h, &w);
if(h > w) swap(h, w);
if(a <= h && b <= w) puts("YES");
else puts("NO");
}
}
return 0;
}

Codeforces Edu Round 58 A-E的更多相关文章

  1. Codeforces Educational round 58

    Ediv2 58 随手AK.jpg D 裸的虚树,在这里就不写了 E 傻逼贪心?这个题过的比$B$都多.jpg #include <cstdio> #include <algorit ...

  2. Educational Codeforces Round 58 (Rated for Div. 2) 题解

    Educational Codeforces Round 58 (Rated for Div. 2)  题目总链接:https://codeforces.com/contest/1101 A. Min ...

  3. Codeforces Beta Round #54 (Div. 2)

    Codeforces Beta Round #54 (Div. 2) http://codeforces.com/contest/58 A 找子序列 #include<bits/stdc++.h ...

  4. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  5. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  6. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  7. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  8. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  9. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

随机推荐

  1. POSIX条件变量

    条件变量: 当一个线程互斥的访问某个变量时,它可能发现其他线程改变状态之前,它什么都做不了例如:一个线程访问队列时,发现队列为空,它只能等待,直到其他线程将一个节点添加到队列中,这种情况就需要使用条件 ...

  2. rbd的数据在哪里

    创建一个rbd [root@mytest ~]# rbd create test1 --size 4000 查看rbd信息 [root@mytest ~]# rbd info test1 rbd im ...

  3. 自行实现的jar包中,日志库的适配实现

    ​ 日常情况下,我们自己都会自行实现一些基础的jar包,如dao包.service包或一些其他完成特定功能的jar包.如果没有一套调试日志信息,出现问题时想查找问题非常不方便.可能大多数小伙伴都会有自 ...

  4. GreenDao增删改查

    3.GreenDao增删改查 (1)插入 常用API //这是最简单的插入语句,新增一行数据,返回值为行号 public long insert(T entity) //传递一个数组,新增多行数据 p ...

  5. Apache Shiro 1.2.4反序列化漏洞(CVE-2016-4437)复现

    Apache Shiro 1.2.4反序列化漏洞(CVE-2016-4437)复现 环境搭建 docker pull medicean/vulapps:s_shiro_1 docker run -d ...

  6. 面试阿里,字节跳动,华为必须知道的Java创建对象的5种方式

    Java创建对象的5种方式 1.直接new,调用了构造器2.通过clone(),没有调用构造器3.通过反射,调用了构造器4.通过反序列化,没有调用构造器5.通过Unsafe类的allocateInst ...

  7. ABBYY FineReader 14如何查看PDF文档

    使用 ABBYY FineReader,您可以轻松查看和编辑任何类型的 PDF文档,就像是一款功能强大的PDF编辑转换器,不仅如此,它还能够允许您复制其中的文本.图片和表格.本文我们来看看如何从&qu ...

  8. Guitar Pro的10个非常实用的技巧(下)

    Guitar Pro 7具有许多功能和编辑选项,只需点击几下即可随时创建与编辑我们的乐谱,.以下就为大家介绍10个Guitar Pro中实用的技巧,可以大大的节省我们的时间. 上次在<Guita ...

  9. 苹果电脑下载电影教程:如何用folx下载《小妇人》

    由西尔莎罗南.艾玛沃特森等知名影星重新演绎的<小妇人>又带动了新一轮的<小妇人>热潮.这部由露易莎创作的长篇小说,曾被多次拍摄,无论是小说本身,还是其影视资源,都能让观众回味无 ...

  10. idea2020安装破解教程

    申明:本教程 IntelliJ IDEA 破解补丁.激活码均收集于网络,请勿商用,仅供个人学习使用 不花钱 的方式 IDEA 2020.2 激活到 2089 年 idea官网下载安装包:https:/ ...