rated

Educational Codeforces Round 76 (Rated for Div. 2)

筅森魡賤 提交于 2020-02-09 20:46:36
A. Two Rival Students (CF 1257 A) 题目大意 有 \(n\) 个学生,给定两个学生的初始站位,可以交换最多 \(k\) 次相邻学生位置,要求那两个学生相距最远,问该距离是多少? 解题思路 移到边边就好了。 神奇的代码 #include <bits/stdc++.h> #define MIN(a,b) ((((a)<(b)?(a):(b)))) #define MAX(a,b) ((((a)>(b)?(a):(b)))) #define ABS(a) ((((a)>0?(a):-(a)))) using namespace std; typedef long long LL; typedef vector<int> VI; typedef pair<int,int> PII; typedef vector<PII> VPII; typedef vector<LL> VL; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template <typename T> void read(T &x) { int s = 0, c = getchar(); x = 0; while (isspace(c)) c = getchar(); if (c == 45) s = 1, c = getchar();

Educational Codeforces Round 80 (Rated for Div. 2) D题

。_饼干妹妹 提交于 2020-02-03 01:44:23
思路:这题有一特点虽然n很大,但是m很小,且最小值最大化–二分 二分check()怎么写?判断每两两数组得出的数组最小值是否可以大于等于mid; 怎么判断是关键----把每一个数组变成一个01串,若这位大于或等于mid则是1,否则是0,那么两个数组得出的数组的最小值要大于或等于mid,那么对这两个二进制作 | 运算,得到的应该是m个1 # include <cstdio> # include <algorithm> # include <cstring> using namespace std ; const int M = 9 ; const int N = 3e5 + 10 ; const int inf = 0x3f3f3f3f ; int a [ N ] [ M ] ; int n , m , ans1 , ans2 ; int num [ 300 ] ; //2^8-1 = 255 bool isOK ( int x ) { memset ( num , 0 , sizeof ( num ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j < m ; j ++ ) { if ( a [ i ] [ j ] >= x ) sum + = ( 1 << j ) ; } num [

Educational Codeforces Round 81 (Rated for Div. 2) B - Infinite Prefixes

孤者浪人 提交于 2020-02-02 09:39:51
Infinite Prefixes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given string s of length nn consisting of 0-s and 1-s. You build an infinite string t as a concatenation of an infinite number of strings s, or t=ssss…t=ssss… For example, if s= 10010, then t= 100101001010010... Calculate the number of prefixes of tt with balance equal to xx. The balance of some string qq is equal to cnt0,q−cnt1,qcnt0,q−cnt1,q, where cnt0,qcnt0,q is the number of occurrences of 0 in qq, and cnt1,qcnt1,q is the number of occurrences of 1 in qq.

Educational Codeforces Round 81 (Rated for Div. 2)

余生颓废 提交于 2020-02-01 19:53:40
E. Permutation Separation 题目链接: https://codeforces.com/contest/1295/problem/E 题意: 给你一个长度为n的数组,其中 1 ~ n 每个数恰好在该数组中出现一次,并且每个数都有自己的价值 ai 你要在数组中任意位置切一刀使数组划分为左集合和右集合(刚切完左右集合不得为空) 切完后你可以将一个集合的任意一个元素 x 丢到另一个集合去,但是你需要支付 a[x]的代价 现要使操作结束后右集合的元素均大于左集合的元素(或其中任意一集合为空集),问你最小代价是多少 分析: 先模拟一遍 假设 n = 6,数组的元素分别为 3,6,5,4,1,2 ,那么我们可以切的位置分别有3,6、6,5、5,4、4,1、1,2之间 我们将每一个可以切的间隙从左往右进行编号,并定义为切点, 如图所示: 其中 1 左边的切点有①②③④,右边的切点有⑤ 2 左边的切点有①②③④⑤,右边没有切点 3 左边没有切点,右边的切点有①②③④⑤ ...... 在开始之前,我们还要知道当我们操作完之后,左集合要么为空,要么剩余 m 个元素,而剩余的元素分别是1 ~ m 好了在了解完以上后,我们采用边枚举边更新的方法 首先, 让我们用pos[i] 表示第 i 个元素的位置,其中pos[1] = 5,pos[2] = 6,pos[3] = 1... 用sum

Educational Codeforces Round 81 (Rated for Div. 2)

孤者浪人 提交于 2020-02-01 18:01:15
A. Display The Number 题意: 告诉你摆出每个数字需要的火柴数,现在给你n跟火柴问能摆出的最大数字是多少 思路: ①当n为奇数:7111.. ②当n为偶数:1111.. #include<iostream> #include<algorithm> #include<cstring> using namespace std; int main() { int t,n; scanf("%d",&t); while(t--){ scanf("%d",&n); if(n%2==0){ for(int i=1;i<=n/2;i++) cout<<1; cout<<endl; continue; } else{ cout<<7; for(int i=1;i<=(n-3)/2;i++) cout<<1; cout<<endl; continue; } } return 0; } B. Infinite Prefixes 题意: 给出一个字符串01串s,s可以无限次重复(例如s=010,可以重复为010010..),给出一个x,求出满足cnt0(串中0的个数)-cnt1(串中1的个数)=x的串的个数,如果有无限个,输出-1 思路: 记 cnt[i]=cnt0(i)-cnt1(i) (从0-i位置中,0的个数与1的个数的差值) ①首先考虑无限的情况:如果 cnt[n-1]=0

Educational Codeforces Round 81 (Rated for Div. 2)

南笙酒味 提交于 2020-01-31 11:54:02
结果:2350/9339 C挂了,恶心人啊,cf电脑一直登不上,还是手机查的,这场比赛好气啊; A. Display The Number 解法:若n为偶数,输出n/2个1;若n为奇数,输出7和(n-3)/2个1. WA点:7放后面WA了一发。 ACODE: /*by freesteed*/ # include <bits/stdc++.h> using namespace std ; # define rep(i,a,n) for (int i=a;i<n;i++) # define per(i,a,n) for (int i=n-1;i>=a;i--) # define pb push_back # define mp make_pair # define fill(x,c) memset(x,c,sizeof(x)) # define all(x) (x).begin(),(x).end() # define fi first # define se second # define SZ(x) ((int)(x).size()) typedef vector < int > VI ; typedef long long ll ; typedef pair < int , int > PII ; typedef double db ; mt19937 mrand (

Educational Codeforces Round 59 (Rated for Div. 2)

北慕城南 提交于 2020-01-31 11:41:02
A.Digits Sequence Dividing 题意:给你一个1-9的数字字符串,把它划分成若干段(>=2)段,使其大小递增。 错误:当长度为2的时候没考虑 #include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<map> using namespace std; typedef long long ll; const int p=998244353; int n,q; char s[1010]; int main() { scanf("%d",&q); for(int i=1;i<=q;i++) { scanf("%d",&n); scanf("%s",s); if(s[0]<s[1]||n>2) { printf("YES\n"); printf("2\n"); printf("%c ",s[0]); for(int j=1;j<n;j++) printf("%c",s[j]); printf("\n"); } else{ printf("NO\n"); } } } View Code B.Digital root 题意:求第k大的数根为x的数 补充知识: 数根(digital root

Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 【数学+分块】

烂漫一生 提交于 2020-01-31 11:40:09
一、题目    D. Yet Another Subarray Problem 二、分析   公式的推导时参考的 洛谷聚聚们的推导   重点是公式的推导,推导出公式后,分块是很容易想的。但是很容易写炸。   1 有些地方容易溢出,这和设置的无穷大的值的大小也有关。   2 如果每次确定了边界$r$,那么在枚举$m$的余数的情况时,一定注意到比$r$大的还不能枚举。 三、AC代码 1 #include <bits/stdc++.h> 2 3 using namespace std; 4 #define Min(a, b) ((a)<(b)?(a):(b)) 5 #define Max(a, b) ((a)>(b)?(a):(b)) 6 typedef long long ll; 7 const int maxn = 3e5 + 13; 8 const ll inf = 1e15 ; 9 int n, m; 10 ll k; 11 int a[maxn]; 12 ll sum[maxn]; 13 ll D[maxn]; 14 ll Dmin[15]; 15 16 int main() 17 { 18 //freopen("input.txt", "r", stdin); 19 while(scanf("%d %d %I64d", &n, &m, &k) != EOF) 20 { 21

Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 背包dp

二次信任 提交于 2020-01-31 11:39:41
D. Yet Another Subarray Problem You are given an array \(a_1, a_2, \dots , a_n\) and two integers \(m\) and \(k\) . You can choose some subarray \(a_l, a_{l+1}, \dots, a_{r-1}, a_r\) . The cost of subarray \(a_l, a_{l+1}, \dots, a_{r-1}, a_r\) is equal to \(\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil\) , where \(\lceil x \rceil\) is the least integer greater than or equal to \(x\) . The cost of empty subarray is equal to zero. For example, if \(m = 3\) , \(k = 10\) and \(a = [2, -4, 15, -3, 4, 8, 3]\) , then the cost of some subarrays are: \(a_3 \dots a_3: 15 - k \lceil

Codeforces Round 81 (Rated for Div. 2) A Display The Number

廉价感情. 提交于 2020-01-31 04:45:21
A Display The Number You have a large electronic screen which can display up to 998244353998244353 decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of 77 segments which can be turned on and off to compose different digits. The following picture describes how you can display all 1010 decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display 11, you have to turn on 22 segments of the screen, and if you want to display 88, all 77