Codeforces
Luo_Xubo
You and your research
展开
-
Codeforces Round686 div3
A思路:按照奇偶性对n进行分类:偶数直接相邻的两两互换;奇数则将前面n-3个相邻的两两互换,后面三个保证合法即可codes:#include <bits/stdc++.h>using namespace std;const int N = 1e6+10;typedef long long LL;int test=1;int n;int main(){ scanf("%d",&test); while(test--) { cin >> n;原创 2020-12-02 21:37:32 · 151 阅读 · 0 评论 -
Codeforces Round#687 div2
A思路:比较四个角上的点,找出它们中距离(r,c)点的最大值code#include <bits/stdc++.h>using namespace std;int t,n,m,r,c;int main(){ cin >> t; while(t--) { scanf("%d %d %d %d", &n, &m, &r, &c); cout << max(max(r+c-2, n+m-r-c), max(n-r+原创 2020-11-30 14:53:33 · 235 阅读 · 2 评论 -
Codeforces Educational Round #98D
D思路:首先确定概率值:因为每一个信号塔有信号的可能性是1/2,所以可以确定分母就是2^n;再看分子,其实就是求有多少种可能性,不难发现,如果开一个数组的话,a[1] = 1, a[2] = 1,此后a[n] = a[n-1] + a[n-2],分子即为a[n]所以概率值为a[n]再利用逆元进行分数取模,注意在每一个可能溢出的地方取模代码:#include <bits/stdc++.h>using namespace std;const int N = 1e6+10;typed原创 2020-11-21 08:47:49 · 221 阅读 · 0 评论 -
Codeforces Educational Round #98 C
C思路:括号匹配问题的变形代码:#include <bits/stdc++.h>using namespace std;const int N = 1e6+10;typedef long long LL;int test=1;string s;int main(){ scanf("%d",&test); while(test--) { cin >> s; int q1=0,q2=0; int res=0; for(int i=0;i原创 2020-11-21 08:43:37 · 134 阅读 · 0 评论 -
Codeforces Educational Round #98 B
B#include <bits/stdc++.h>using namespace std;const int N = 1e6+10;typedef long long LL;int test=1;int n,a[N];LL sum,k;int maxn;int main(){ scanf("%d",&test); while(test--) { sum = k = 0; maxn = 0; cin >> n; for(int i=0原创 2020-11-21 08:42:33 · 129 阅读 · 0 评论 -
Codeforces Educational Round#98 A
A思路:考虑三种可能:要不要换,换1,换0代码:#include <bits/stdc++.h>using namespace std;const int N = 1e6+10;typedef long long LL;int test=1;int main(){ scanf("%d",&test); while(test--) { int x,y; cin >> x >> y; if(abs(x-y)<=1)原创 2020-11-21 08:40:35 · 215 阅读 · 0 评论 -
Codeforces Round#684div2
B思路先看每组数据的最后一个取数点:也就是说要想获得尽可能大的中位数,那么至少要保证最后一个中位数所在的子数组里面,至少有n/2个元素比他大,这样得出最后一个中位数的位置为 n*k - n/2再看步长:要想使每个子数组的长度为n,现在我们已经有了1 + floor(n/2) 个元素,也就是说仍需要 n/2 + 1个元素,所以步长设为n/2+1再看最小的那个中位数该取谁:要想使该元素变为中位数,那么至少有(n-1)/2个元素小于他,同时有k组,那么我们要给这k组一共流出(n-1)/2*k个元素来原创 2020-11-18 23:51:10 · 142 阅读 · 0 评论 -
Codeforces Round#684div2 A
A思路:判断三种情况:不需要改变0->11->0代码#include <bits/stdc++.h>using namespace std;const int N = 1e5+10;typedef long long LL;int test=1;int n,c0,c1,h;string s;int main(){ scanf("%d", &test); while(test--) { cin >> n >>原创 2020-11-18 23:43:56 · 113 阅读 · 0 评论 -
Codeforces Edu89 div2D
Codeforces Edu89 div2D原题:You are given n integers a1,a2,…,an.For each ai find its two divisors d1>1 and d2>1 such that gcd(d1+d2,ai)=1 (where gcd(a,b) is the greatest common divisor of a and b) or say that there is no such pair.InputThe first li原创 2020-06-13 13:52:10 · 236 阅读 · 0 评论 -
Codeforces Educational Round89div2C
Codeforces Educational Round89 div2C原题:You are given a matrix with n rows (numbered from 1 to n) and m columns (numbered from 1 to m). A number ai,j is written in the cell belonging to the i-th row and the j-th column, each number is either 0 or 1.A chi原创 2020-06-13 13:32:35 · 251 阅读 · 0 评论 -
Codeforces Educational Round89div2
Codeforces Educational Round89div2原题:You are given an array consisting of n integers a1, a2, …, an. Initially ax=1, all other elements are equal to 0.You have to perform m operations. During the i-th operation, you choose two indices c and d such that l原创 2020-06-13 13:28:57 · 281 阅读 · 0 评论 -
Codeforces Educational Round89 div2A
Codeforces Educational Round89div2A原题Polycarp plays a well-known computer game (we won’t mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a swor原创 2020-06-13 13:26:44 · 205 阅读 · 0 评论 -
Codeforces648div2D
Codeforces648div2D原题:Vivek has encountered a problem. He has a maze that can be represented as an n×m grid. Each of the grid cells may represent the following:Empty — ‘.’Wall — ‘#’Good person — ‘G’Bad person — ‘B’The only escape from the maze is at原创 2020-06-08 08:28:19 · 217 阅读 · 0 评论 -
Codeforces648div2C
Codeforces648div2C原题:After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let’s call them a and b原创 2020-06-08 08:25:33 · 303 阅读 · 0 评论 -
Codeforces648div2B
Codeforces648div2B原题:Ashish has n elements arranged in a line.These elements are represented by two integers ai — the value of the element and bi — the type of the element (there are only two possible types: 0 and 1). He wants to sort the elements in no原创 2020-06-08 08:23:35 · 236 阅读 · 0 评论 -
Codeforces648div2A
Codeforces648div2A原题:Ashish and Vivek play a game on a matrix consisting of n rows and m columns, where they take turns claiming cells. Unclaimed cells are represented by 0, while claimed cells are represented by 1. The initial state of the matrix is giv原创 2020-06-08 08:21:28 · 226 阅读 · 0 评论 -
Codeforces647div2C
Codeforces647div2C原题:The last contest held on Johnny’s favorite competitive programming platform has been received rather positively. However, Johnny’s rating has dropped again! He thinks that the presented tasks are lovely, but don’t show the truth abou原创 2020-06-06 00:18:07 · 174 阅读 · 0 评论 -
Codeforces 647div2B
Codeforces 647div2B原题:Among Johnny’s numerous hobbies, there are two seemingly harmless ones: applying bitwise operations and sneaking into his dad’s office. As it is usually the case with small children, Johnny is unaware that combining these two activi原创 2020-06-06 00:16:52 · 230 阅读 · 0 评论 -
Codeforces 647div2A
Codeforces #647div2 A原题:Johnny has recently found an ancient, broken computer. The machine has only one register, which allows one to put in there one variable. Then in one operation, you can shift its bits left or right by at most three positions. The r原创 2020-06-06 00:15:19 · 159 阅读 · 0 评论 -
Codeforces645div2
Codeforces #645div2A链接思路:规律题,一个路灯照两个格子,用最少的路灯覆盖所有格子ACcodes:#include <bits/stdc++.h>using namespace std;const int N = 2e5+10;int test = 1;int n,m,a[N];int main(){ scanf("%d",&test); while(test--) { cin >> n >> m; if(n原创 2020-05-27 08:44:19 · 353 阅读 · 0 评论 -
Codeforces644div3
Codeforces #644 div3听说是div4改成的div3,然而我还是没有ak…A题目链接思路:规律题ACcodes:#include <bits/stdc++.h>using namespace std;const int N = 2e5+10;int test = 1;int n;int a,b;int main(){ scanf("%d",&test); while(test--) { cin >> a >>原创 2020-05-25 09:36:05 · 339 阅读 · 0 评论 -
Codeforces educational round #87 A~D
A原题链接思路: 模拟找规律代码:#include <bits/stdc++.h>using namespace std;const int N = 2e5+10;int test=1;//int n,a[N]; int a,b,c,d;int main(){ scanf("%d",&test); while(test--) { scanf("%d %d %d %d", &a, &b, &c, &d); if(b&原创 2020-05-18 23:09:07 · 297 阅读 · 0 评论 -
Codeforces #642 div3 D
Codeforces #642div3 D原题链接解析:优先队列模拟ACcodes:#include <bits/stdc++.h>using namespace std;const int N = 2e5+10;pair<int,int> a[N];int q[N];void find(int l, int r){ if(l>r) return; int m = (l+r)/2; a[m].first = l-r; a[m].second =原创 2020-05-15 00:57:50 · 209 阅读 · 0 评论 -
Codeforces #642div3 C
Codeforces #642 div3 C原题链接思路:模拟原创 2020-05-15 00:48:51 · 199 阅读 · 0 评论 -
Codeforces #642 div3 B
Codeforces 642 div3 B原题链接思路:把a顺序排,b逆序排ACcodes:#include <bits/stdc++.h>using namespace std;const int N = 2e5+10;long long inf = 0x3f3f3f3f3f3f3f3f;int test = 1;int n,k,a[50],b[50];int main(){ scanf("%d",&test); while(test--) { int原创 2020-05-15 00:46:16 · 272 阅读 · 0 评论 -
Codeforces642div3A
A原题链接解析:规律题,分三个情况,n=1,n=2,其他。代码:#include <bits/stdc++.h>using namespace std;const int N = 2e5+10;long long inf = 0x3f3f3f3f3f3f3f3f;int test = 1;int n,m,a[N];int main(){ scanf("%d",&test); while(test--) { cin >> n >> m原创 2020-05-15 00:37:09 · 167 阅读 · 0 评论 -
Codeforces #641div2 C
Codeforces #641div2 C原题链接在这思路记录下前i-1个数的gcd,lcmACcodes:#include <bits/stdc++.h>using namespace std;long long lcm(long long a, long long b){ return a*b/__gcd(a,b);}int main(){ long long n,a,ans=0,y; cin>>n>>a; lon原创 2020-05-13 01:04:36 · 265 阅读 · 0 评论 -
Codeforces #641div2 B
Codeforces #641div2 B原题链接在这思路:求最长上升子序列的改版ACcodes:#include <bits/stdc++.h>using namespace std;const int N = 2e5+10;long long inf = 0x3f3f3f3f3f3f3f3f;int test = 1;int n,dp[N],a[N];int main(){ scanf("%d",&test); while(test--) {原创 2020-05-13 01:01:51 · 172 阅读 · 0 评论 -
Codeforces #641 div2 A
Codeforces #641 div2 A原题链接在这思路:思维题,分奇偶讨论即可ACcodes:#include <bits/stdc++.h>using namespace std;const int N = 2e5+10;long long inf = 0x3f3f3f3f3f3f3f3f;int test = 1;int n,k,a[N];int main(){ scanf("%d",&test); while(test--) { cin原创 2020-05-13 00:59:45 · 192 阅读 · 0 评论 -
Codeforces#640div4解题报告
Codeforces #640div4A原题A positive (strictly greater than zero) integer is called round if it is of the form d00…0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all原创 2020-05-10 17:08:46 · 352 阅读 · 0 评论 -
Codeforces #639 div2 C
Codeforces #639 div2 C题目链接在这Hilbert’s Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers...原创 2020-05-07 09:12:41 · 322 阅读 · 0 评论 -
Codeforces #639 div2 B
Codeforces #639 div2 B原题连接在这A card pyramid of height 1 is constructed by resting two cards against each other. For h>1, a card pyramid of height h is constructed by placing a card pyramid of hei...原创 2020-05-07 09:10:20 · 347 阅读 · 0 评论 -
Codeforces 639div2 A
Codeforces 639 div2 A原题连接在这You are given a special jigsaw puzzle consisting of n⋅m identical pieces. Every piece has three tabs and one blank, as pictured below.The jigsaw puzzle is considered sol...原创 2020-05-07 09:07:58 · 261 阅读 · 0 评论 -
Codeforces #635 div2 C
#635 div2 C题目描述Writing light novels is the most important thing in Linova’s life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as sh...原创 2020-04-29 00:08:51 · 162 阅读 · 0 评论 -
Codeforces #635 div2 B
Codeforces #635 div2 B题目描述Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.One d...原创 2020-04-29 00:03:57 · 261 阅读 · 0 评论 -
Codeforces #635 div2 A
#635 div2 A题目描述Ichihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears.These days the temple is holding a math contest. Usually, Ichihime lacks in...原创 2020-04-28 23:59:24 · 280 阅读 · 0 评论 -
Codeforces #636 div3 A~D
Codeforces #636 div3 A~DA.题目描述Recently Vova found n candy wrappers. He remembers that he bought x candies during the first day, 2x candies during the second day, 4x candies during the third day, …,...原创 2020-04-28 23:53:52 · 237 阅读 · 0 评论 -
Codeforces #630 div2 C // 1332C
Codeforces #630 div2 C题目描述Word s of length n is called k-complete ifs is a palindrome, i.e. si=sn+1−i for all 1≤i≤n;s has a period of k, i.e. si=sk+i for all 1≤i≤n−k.For example, “abaaba” is a 3-...原创 2020-04-23 21:14:37 · 196 阅读 · 0 评论