Educational Codeforces Round 89 (Rated for Div. 2)

A. Shovels and Swords

思路

题意非常简单,就是得到最多的物品嘛,我们假定a,ba, ba,b中aaa是最小的一个,分两种情况。

如果2∗a<=b2 * a <= b2∗a<=b,那么我们只需要购买花费是1,21, 21,2的东西即可,也就是最后能购买得到aaa件物品。

否则的话,我们一定是先让数量更多的去减222,用数量更少的去减111,直到两个物品的数量相等,再通过1,21, 21,2,2,12, 12,1的顺序去交换执行,总结一下最后的答案就是(n+m)/3(n + m) / 3(n+m)/3。

代码

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_backusing namespace std;typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;const double eps = 1e-7;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;inline ll read() {ll f = 1, x = 0;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9') {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f * x;
}const int N = 2e5 + 10;int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int t = read();while(t--) {ll a = read(), b = read();if(a > b)   swap(a, b);if(a * 2 <= b)  printf("%lld\n", a);else    printf("%lld\n", (a + b) / 3);}return 0;
}

B.Shuffle

思路

就是一个区间有重合判断并集的问题,如果我们给定的区间[l,r][l, r][l,r]在原本的区间外也就是r<L∣∣l>Rr < L || l > Rr<L∣∣l>R,否则的话我们就更新L,RL, RL,R的最大最小值

代码

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_backusing namespace std;typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;const double eps = 1e-7;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;inline ll read() {ll f = 1, x = 0;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9') {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f * x;
}const int N = 2e5 + 10;int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int t = read();while(t--) {int n = read(), x = read(), m = read();int l = x, r = x;// cout << l << " " << r << endl;for(int i = 1; i <= m; i++) {int a = read(), b = read();if((a <= r && a >= l) || (b >= l && b <= r) || (l >= a && b >= r)) {//比赛时判断条件写的比较繁琐。l = min(l, a);r = max(r, b);}// cout << l << " " << r << endl;}printf("%d\n", r - l + 1);}return 0;
}

C.Palindromic Paths

思路

开两个数组,num1[i]num1[i]num1[i]记录的是步数为iii的时候的位置上的111的个数,num0[i]num0[i]num0[i]记录的是步数为iii的时候的位置上000的个数,因为整体的步数就是在[1,n+m−1][1, n + m - 1][1,n+m−1]之间,所以我们可以通过对每一步全变为000或者全变为111中挑选一个最小值,作为我们的花费,然后累加花费就是答案。

代码

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_backusing namespace std;typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;const double eps = 1e-7;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;inline ll read() {ll f = 1, x = 0;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9') {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f * x;
}const int N = 2e5 + 10;int a[40][40];int num0[100], num1[100];int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int t = read();while(t--) {memset(num1, 0, sizeof num1);memset(num0, 0, sizeof num0);int n = read(), m = read();// cout << n << " " << m << endl;for(int i = 1; i <= n; i++)for(int j = 1; j <= m; j++) {a[i][j] = read();if(a[i][j] == 1)    num1[i + j]++;else num0[i + j]++;}if(n == 2 && m == 2) {puts("0");// puts("");continue;}int ans = 0;int l = 2, r = n + m;while(l < r) {//好像这个if语句并没有什么用,不知道比赛的时候怎么想的。if((num1[l] && num0[l]) || (num1[r] && num0[r]) || (num1[l] && num0[r]) || (num0[l] && num1[r]))ans += min(num0[l]+ num0[r], num1[l] + num1[r]);// cout << ans << "\n";l++, r--;}printf("%d\n", ans);// puts("");}return 0;
}

D.Two Divisors

思路

先引入一个定理gcd(a,b)=1=gcd(a+b,a∗b)gcd(a, b) = 1 = gcd(a + b, a * b)gcd(a,b)=1=gcd(a+b,a∗b),所以这道题就简简单单就可以水过了,但是我的赛况却不是如此,,,,,

那我们来证明一下这个定理的正确性吧:

假设有KaTeX parse error: Undefined control sequence: \and at position 15: gcd(x, y) = 1 \̲a̲n̲d̲ ̲gcd(x, z) = 1,所以gcd(x,y∗z)=1gcd(x, y * z) = 1gcd(x,y∗z)=1

gcd(a,b)=1−>gcd(a+b,b)=1=gcd(a,a+b)−>gcd(a+b,a∗b)=1gcd(a, b) = 1 -> gcd(a + b, b) = 1 = gcd(a, a + b) - > gcd(a + b, a * b) = 1gcd(a,b)=1−>gcd(a+b,b)=1=gcd(a,a+b)−>gcd(a+b,a∗b)=1

代码

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_backusing namespace std;typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;const double eps = 1e-7;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;inline ll read() {ll f = 1, x = 0;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9') {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f * x;
}const int N1 = 1e7 + 10, N2 = 5e5 + 10;int prime[N1], cnt;
int ans1[N2], ans2[N2], n;
bool st[N1];int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);for(int i = 2; i < N1; i++) {if(!st[i])  prime[++cnt] = i;for(int j = 1; j <= cnt && i * prime[j] < N1; j++) {st[i * prime[j]] = true;if(i % prime[j] == 0)   break;}}n = read();for(int i = 1; i <= n; i++) {int temp = read();ans1[i] = ans2[i] = -1;for(int j = 1; prime[j] * prime[j] <= temp; j++) {int x = 1;if(temp % prime[j] == 0) {while(temp % prime[j] == 0) {temp /= prime[j];x *= prime[j];}if(temp == 1)   break;else {ans1[i] = x;ans2[i] = temp;break;}}}}for(int i = 1; i <= n; i++)printf("%d%c", ans1[i], i == n ? '\n' : ' ');for(int i = 1; i <= n; i++)printf("%d%c", ans2[i], i == n ? '\n' : ' ');return 0;
}

Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)相关推荐

  1. Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...

  2. Educational Codeforces Round 123 (Rated for Div. 2)(ABCDE)

    Educational Codeforces Round 123 (Rated for Div. 2)(ABCDE) A. Doors and Keys 题意:给定长度为6的字符串,问是否可以通关,其 ...

  3. Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)

    Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...

  4. Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...

  5. Educational Codeforces Round 112 (Rated for Div. 2)(A-D)

    Educational Codeforces Round 112 (Rated for Div. 2) A 我写的挺烦的,其实判断一下奇偶数和有没有a>0就行 #include <bits ...

  6. Educational Codeforces Round 61 (Rated for Div. 2)(A、B、C、D、E、F)

    欢迎访问本菜鸡的独立博客:Codecho 比赛名称 Educational Codeforces Round 61 (Rated for Div. 2) 比赛链接 https://codeforces ...

  7. Educational Codeforces Round 133 (Rated for Div. 2)(CD题解)

    Educational Codeforces Round 133 (Rated for Div. 2)CD题解 过AB补CD C. Robot in a Hallway 题意 题意:现有 2∗m 的方 ...

  8. Educational Codeforces Round 89 (Rated for Div. 2) D. Two Divisors(数论)

    题目链接 题目大意 让你找出x的两个因子d1>1,d2>1使得gcd(d1+d2,x)=1 题目思路 首先要明白gcd的性质 gcd(a,b)=gca(a+b,b) if(gcd(a,c) ...

  9. Educational Codeforces Round 88 (Rated for Div. 2)(AB)

    Berland Poker CodeForces - 1359A 代码如下: #include<bits/stdc++.h> #define ll long long using name ...

最新文章

  1. Scrum卡片层次图
  2. JS实现HTML上用button打开文件对话框
  3. vue click事件冒泡,默认行为
  4. 小朋友嘴里的“金钥匙”,良品小食仙、小鹿蓝蓝们要如何拿到?
  5. 使用nsenter进入docker容器后端报错 mesg: ttyname failed: No such file or directory
  6. java隐藏与覆盖_java中方法的隐藏和覆盖问题?
  7. JQuery EasyUI DataGrid 、tree查询
  8. 公众号支付相关需要注意的问题
  9. V神演讲干货全送上!关于以太坊2.0,你想知道的都在这里!
  10. ImportError: cannot import name ‘activations‘ from ‘keras.layers‘
  11. 心理平衡其实就这么简单
  12. CTFWeb——Bugku秋名山老司机 详细题解
  13. 无法访问此网站 localhost 拒绝了我们的连接请求。
  14. Assert.assertNotNull()断言是否是空
  15. Linux (redhat)封装虚拟机镜像
  16. SAP FICO 定义成本组件结构
  17. 网络安全(一):常见的网络威胁及防范
  18. 1.24A Simple Math Problem
  19. H - 找女朋友(快排)
  20. SATA硬盘与IDE硬盘的优劣势对比

热门文章

  1. 语言 ota_荣威RX5 PLUS使用最新的家族设计语言,给人更年轻时尚的感觉
  2. 外圆内方与外方内圆的奇妙变换!
  3. 女孩子狠起来可以多可怕?
  4. 为什么说减速带是脑残的设计?
  5. 如果你没空读书,就一定要来看看这8个公众号!
  6. 94年出生,她们如今都是985高校博士生导师!
  7. 如何使用TensorFlow玩转深度学习?
  8. 计算机老师开场白试讲视频,教师招考试讲模版之开场白
  9. java中string 和stringbuffer的区别_Java中的String,StringBuilder,StringBuffer三者的区别...
  10. Java开发面试高频考点学习笔记(每日更新)