rated

Educational Codeforces Round 68 (Rated for Div. 2)---B

好久不见. 提交于 2019-12-20 04:11:44
http://codeforces.com/contest/1194/problem/B 1 /* */ 2 # include <bits/stdc++.h> 3 using namespace std; 4 5 int r[50005], c[50005]; 6 string s[50005]; 7 8 int main() 9 { 10 int n, m, q; 11 scanf("%d", &q); 12 while( q-- ) 13 { 14 scanf("%d %d", &n, &m); 15 for(int i=0; i<n; i++ ) 16 cin>>s[i]; 17 int cnt = 0; 18 for( int i=0; i<n; i++ ) 19 { 20 cnt=0; 21 for( int j=0; j<m; j++ ) 22 { 23 if( s[i][j]=='.' ) 24 cnt++; 25 } 26 r[i] = cnt; 27 } 28 for( int j=0; j<m; j++ ) 29 { 30 cnt = 0; 31 for( int i=0; i<n; i++ ) 32 { 33 if( s[i][j]=='.' ) 34 cnt++; 35 } 36 c[j] = cnt; 37 } 38 int ans = 50005;

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

可紊 提交于 2019-12-18 01:08:47
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接: https://codeforces.com/contest/1101 A. Minimum Integer 题意: 多组数据,给你三个数l,r,d,要求在区间[l,r]之外找一个最小的x,使得x%d==0。 题解: 当d<l or d>r的时候,直接输出d就好了。 当l<=d<=r的时候,找到最小的t,使得t*d>r就行了。 具体操作见代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; int q; ll l,r,d; int main(){ cin>>q; while(q--){ cin>>l>>r>>d; if(d<l || d>r) cout<<d<<endl; else{ ll now = r/d; cout<<(now+1)*d<<endl; } } return 0; } View Code B. Accordion 题意: 给出一个字符串,要求删去一些数后它由以下几个部分组成,[ : .... : ],这其中"...."指的是0个或多个“ | ”。 问满足上面条件时,留下的字符串的最大长度为多少。 题解: 模拟一下就好了,从左往右遍历找 [ 以及 :

Educational Codeforces Round 77 (Rated for Div. 2) C. Infinite Fence

家住魔仙堡 提交于 2019-12-06 10:56:50
C. Infinite Fence 题目大意:给板子涂色,首先板子是顺序的,然后可以涂两种颜色,如果是r的倍数涂成红色,是b的倍数涂成蓝色, 连续的k个相同的颜色则不能完成任务,能完成任务则输出OBEY,否则输出REBEL 首先我们可以求b,r的gcd d=gcd(b,r) 然后b/=d,r/=d 然后让r<b if(r>b) swap(b,r) 然后如果要连续k个板子颜色涂成r,则要占的长度是 len = r*(k-1)+1 如果这个长度len>b 则可以完成,否则不可以完成 这个原因应该很好理解,但是为什么b,r 要先处理一下都除以d呢? 这个是因为如果b,r 不互质,则它们有一个最大公约数,所以他们每走一步都是最大公约数的整数倍数 如果本来就互质,那么最大公约数就是1,如果不互质,那么这个最大公约数d,其实就相当于这个1 所以除以d 不会影响结果。 #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <iostream> #include <map> #include <vector> #define inf 0x3f3f3f3f-= #define debug(x) cout<<"x = "<<x<<endl; using namespace std;

Educational Codeforces Round 77 (Rated for Div. 2)

微笑、不失礼 提交于 2019-12-06 01:51:41
传送门 感觉最近写代码的状态有点迷...还好这次最后两分钟过了D,不然就掉分了QAQ。 A. Heating 签到。 Code /* * Author: heyuhhh * Created Time: 2019/11/27 21:53:49 */ #include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <set> #include <map> #include <iomanip> #define MP make_pair #define fi first #define se second #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define INF 0x3f3f3f3f #define Local #ifdef Local #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0) void err() { std::cout << '\n'; } template<typename T, typename...Args> void err(T a, Args...args) {

Educational Codeforces Round 77 (Rated for Div. 2)D(二分+贪心)

大兔子大兔子 提交于 2019-12-06 01:17:48
这题二分下界是0,所以二分写法和以往略有不同,注意考虑所有区间,并且不要死循环。。。 1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 int m,n,k,t; 5 int a[200007]; 6 int x[200007],y[200007],z[200007]; 7 int sum[200007]; 8 int check(int v){ 9 memset(sum,0,sizeof(sum)); 10 for(int i=1;i<=k;++i) 11 if(z[i]>v) 12 ++sum[x[i]],--sum[y[i]+1]; 13 int temp=0; 14 for(int i=1;i<=n;++i){ 15 sum[i]+=sum[i-1]; 16 if(sum[i]) 17 temp+=2; 18 } 19 if(temp<=t) 20 return 1; 21 return 0; 22 } 23 int main(){ 24 ios::sync_with_stdio(false); 25 cin.tie(NULL); 26 cout.tie(NULL); 27 cin>>m>>n>>k>>t; 28 for(int i=1;i<=m;++i) 29

Educational Codeforces Round 77 (Rated for Div. 2)

社会主义新天地 提交于 2019-12-06 01:12:10
Educational Codeforces Round 77 (Rated for Div. 2) A. Heating 题意:n组数据,每组数据告诉你有c i 个数,他们的和为sum i ,求他们平方的和最小是多少。 思路:对于每组数据让c i 个数尽可能的相等。(均值不等式可推) #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); long long n; cin>>n; while(n--){ long long c,sum; cin>>c>>sum; long long small_num=sum/c,big_num,ans=0; if(sum%c==0){ ans=small_num*small_num*c; }else{ big_num=small_num+1; long long cont_big=sum%c; long long cont_small=c-cont_big; ans=big_num*big_num*cont_big+small_num*small_num*cont_small; } cout<<ans<<endl; } return 0; } View Code B. Obtain

Educational Codeforces Round 77 (Rated for Div. 2)

落爺英雄遲暮 提交于 2019-12-05 23:31:20
A. Heating (CF 1260 A) 题目大意:n组数据,每组数据有两个数c i 和sum i ,选择c i 个非负数a i ,使得$\sum ^{c_{i}}_{k=1}a_{k}\geq sum_{i}$,且最小化$\sum ^{c_{i}}_{k=1}a^{2}_{k}$,求最小值。 由均值不等式可知当每个a k =$\dfrac {sum_{i}}{c_{i}}$时有最小的$\sum ^{c_{i}}_{k=1}a^{2}_{k}$,但a i 需要整数,那我们先对前x个数取a+1,直到剩下的c i -x个数都取a时有$\sum ^{c_{i}}_{k=1}a_{i}=sum_{i}$,此时$\sum ^{c_{i}}_{k=1}a^{2}_{k}$最小。 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 template <typename T> 5 void read(T &x) { 6 int s = 0, c = getchar(); 7 x = 0; 8 while (isspace(c)) c = getchar(); 9 if (c == 45) s = 1, c = getchar(); 10 while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^

Educational Codeforces Round 77 (Rated for Div. 2)

陌路散爱 提交于 2019-12-05 22:55:12
A - Heating 题意:一个房间,最多装c个加热器,若某个加热器长度为k,则花费为k*k,覆盖这n个长度求最小花费。 题解:首先每个格子只装最多一个,先取min。然后肯定是最平均最好,小平均值是n/d取下整,大平均值是小平均值+1,大平均值的个数是n%d,小平均值的个数即剩下的。 #include<bits/stdc++.h> using namespace std; typedef long long ll; void test_case() { ll r, b, k; scanf("%lld%lld%lld", &r, &b, &k); if(r > b) swap(r, b); ll g = __gcd(r, b); r /= g, b /= g; ll suc = ((b - 1) >= (k - 1) * r + 1); if(suc) { puts("REBEL"); return; } else { puts("OBEY"); return; } } int main() { #ifdef KisekiPurin freopen("KisekiPurin.in", "r", stdin); #endif // KisekiPurin int t = 1; scanf("%d", &t); for(int ti = 1; ti <= t; ++ti) { /

Educational Codeforces Round 77 (Rated for Div. 2)

空扰寡人 提交于 2019-12-05 20:51:31
A. Heating Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house. Your house has n n rooms. In the i i-th room you can install at most c i ci heating radiators. Each radiator can have several sections, but the cost of the radiator with k k sections is equal to k 2 k2 burles. Since rooms can have different sizes, you calculated that you need at least s u m i sumi sections in total in the i i-th room. For each room calculate the minimum cost to install at most c i ci

Educational Codeforces Round 48 (Rated for Div. 2)

戏子无情 提交于 2019-12-05 04:02:59
又是回忆场。 A - Death Note 题意:有一本笔记,你在第i天连续写ai个字,每写满m个字强制翻页(不管还要不要写),求第i天翻了多少页。 题解:那么当前的页数就是下整+1(其实不加也可以,从0开始),直接模拟即可,我当时写的什么东西? 注意溢出。 #include<bits/stdc++.h> using namespace std; typedef long long ll; void test_case() { int n, m; scanf("%d%d", &n, &m); ll cur = 0, px = 1; for(int i = 1; i <= n; ++i) { int ai; scanf("%d", &ai); cur += ai; ll cx = (cur / m) + 1; printf("%lld%c", cx - px, " \n"[i == n]); px = cx; } } int main() { #ifdef KisekiPurin freopen("KisekiPurin.in", "r", stdin); #endif // KisekiPurin int t = 1; for(int ti = 1; ti <= t; ++ti) { //printf("Case #%d: ", ti); test_case(); } } B -