rated

Educational Codeforces Round 76 (Rated for Div. 2) - D. Yet Another Monster Killing Problem(贪心)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 21:56:15
题意:有$n$个怪物,每个怪物有一个能力值$a[i]$,你现在有$m$个英雄,每个英雄有两个属性:$p[i]$表示这个英雄的能力值,$s[i]$表示这个英雄的耐力值,即一天内最多能消灭$s[i]$个怪物,每一天你可以选择一个英雄去消灭怪物,并且你只能一个一个的消灭,不能改变顺序,当一个英雄的能力值大于等于怪物的能力值并且他这一天内消灭的怪物数小于$s[i]$时,他就会继续去消灭下一个怪物,直到消灭的怪物数量等于$s[i]$或者这个英雄的能力值小于当前怪物的能力值,结束这一天,进入第二天,一个英雄可以使用多次,问消灭所有怪物最少的天数。 思路:当英雄最大的能力值小于怪物最大的能力值时,不可能把所有怪物消灭,直接输出$-1$,考虑有解时,显然当两个英雄的耐力值$s[i]$相等时,我们会选择能力值大的那个英雄去消灭怪物,所以我们定义$b[i]$表示耐力值至少为$i$(至少能消灭$i$只怪)的英雄中最大的能力值,显然$b[i]$从$n$到$1$是非递减的。设在某一天内已经消灭了$k$只怪物,因为一天只能选择一个英雄,所以在消灭第$k+1$只怪物时,如果这一天内怪物能力的最大值$now$大于$b[k+1]$,则应该结束这一天,第二天又从最大值$b[1]$开始消灭怪物。 注意:$b[i]$数组的求法,从后先前,每次$b[i]=max(b[i],b[i+1])$ #include

Educational Codeforces Round 51 (Rated for Div. 2)

僤鯓⒐⒋嵵緔 提交于 2019-12-04 21:18:17
http://codeforces.com/contest/1051 随手捞到的以前没有补完的场, D. Bicolorings 一个dp题,题意是,有一个2*n的矩阵,其中每个色块可黑可白,重要的是里面的连通块数,题目将给出n和k,让你求恰好有k个连通块的情况下的方案数。 从列来考虑,假设已知前一个矩阵的最后一列,和其方案数,(可以用00、01、10、11的二进制数来表示)那么当前dp[i][K][0]表示第i列有K个连通块且末尾列为00的方案数 前一列可能是00、01、10、11其中任何一个,分别加上00时连通块个数的状态为不变、+1、+1、+1,于是有dp[i][K][0] = dp[i-1][K][0] + dp[i-1][K-1][1] + dp[i-1][K-1][2] + dp[i-1][K-1][3]; 其他情况类比推理一下就好了,要注意的地方是取模,分分钟爆int所以每次加法都要取一次mod最后出结果的时候也是 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int mod =998244353 ; 5 int n,T,k,dp[1200][2400][5]; 6 ll temp; 7 8 int main(){ 9 10 cin>>n>>k; 11

Educational Codeforces Round 76 (Rated for Div. 2)E(最长上升子序列)

ぃ、小莉子 提交于 2019-12-04 18:01:37
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; int a[200007],b[200007],c[200007]; int cnt1[200007],cnt2[200007],cnt3[200007]; int mn[200007]; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int k1,k2,k3; cin>>k1>>k2>>k3; for(int i=1;i<=k1;++i){ cin>>a[i]; ++cnt1[a[i]]; } for(int i=1;i<=k2;++i){ cin>>b[i]; ++cnt2[b[i]]; } for(int i=1;i<=k3;++i){ cin>>c[i]; ++cnt3[c[i]]; } int n=k1+k2+k3; for(int i=1;i<=n;++i){ cnt1[i]=cnt1[i-1]+cnt1[i];//小于等于i的个数 cnt2[i]=cnt2[i-1]+cnt2[i]; cnt3[i]=cnt3[i-1]+cnt3[i]; } for(int i=0;i<=n;++i) mn[i]=cnt3[i]-cnt2[i]

Educational Codeforces Round 74 (Rated for Div. 2)

风格不统一 提交于 2019-12-04 14:25:20
跳过了一些困难的题开一场新的。看来2100的题还是要慢慢挑战,不能操之过急。 A - Prime Subtraction 题意:给两个数x,y,可以从x中减去任意个相同的质数p,问能不能与y相等。 题解:首先x>=y,然后差值不能为1,否则一定可以。 #include<bits/stdc++.h> using namespace std; typedef long long ll; void test_case() { ll x, y; scanf("%lld%lld", &x, &y); if(x < y || x == y + 1) puts("NO"); else puts("YES"); } int main() { #ifdef KisekiPurin freopen("KisekiPurin.in", "r", stdin); #endif // KisekiPurin int t; scanf("%d", &t); for(int ti = 1; ti <= t; ++ti) { //printf("Case #%d: ", ti); test_case(); } } 来源: https://www.cnblogs.com/KisekiPurin2019/p/11870120.html

Educational Codeforces Round 76 (Rated for Div. 2)

*爱你&永不变心* 提交于 2019-12-04 14:24:50
Educational Codeforces Round 76 (Rated for Div. 2) A: Two Rival Students 水题,找距离最远,特判已经到达端点情况即可 B: Magic Stick 分析 ​ 最开始想是暴力覆盖整个区间,但1e9很显然不可能,分析样例,盲猜只有以下情况是NO ((a==2 || a==3) && b!=3 && b!=2 && b!=1) (a==1 && b!=1) 事实证明是正确的,因为操作中有-1这种微调操作,基本除了小数据会是no其他都是yes 代码 #include <bits/stdc++.h> using namespace std; int main(){ //freopen("test.in","r",stdin); //freopen("test.out","w",stdout); int T,b,a; cin>>T; while(T--){ scanf("%d %d",&a,&b); if(a==1 && b!=1){printf("NO\n");continue;} else if((a==2 || a==3) && b!=3 && b!=2 && b!=1){printf("NO\n");continue;} else {printf("YES\n");continue;} } return 0; }

Educational Codeforces Round 76 (Rated for Div. 2) D. Yet Another Monster Killing Problem

…衆ロ難τιáo~ 提交于 2019-12-04 12:30:28
You play a computer game. In this game, you lead a party of m m heroes, and you have to clear a dungeon with n n monsters. Each monster is characterized by its power a i ai. Each hero is characterized by his power p i pi and endurance s i si. The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day. When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k k monsters, the hero fights with the monster k

Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest

旧时模样 提交于 2019-12-04 12:30:15
A team of three programmers is going to play a contest. The contest consists of n n problems, numbered from 1 1 to n n. Each problem is printed on a separate sheet of paper. The participants have decided to divide the problem statements into three parts: the first programmer took some prefix of the statements (some number of first paper sheets), the third contestant took some suffix of the statements (some number of last paper sheets), and the second contestant took all remaining problems. But something went wrong — the statements were printed in the wrong order, so the contestants have

Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students

烈酒焚心 提交于 2019-12-04 12:29:12
You are the gym teacher in the school. There are n n students in the row. And there are two rivalling students among them. The first one is in position a a, the second in position b b. Positions are numbered from 1 1 to n n from left to right. Since they are rivals, you want to maximize the distance between them. If students are in positions p p and s s respectively, then distance between them is | p − s | |p−s|. You can do the following operation at most x x times: choose two adjacent (neighbouring) students and swap them. Calculate the maximum distance between two rivalling students after at

Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray

不羁的心 提交于 2019-12-04 12:29:05
Let's call an array t t dominated by value v v in the next situation. At first, array t t should have at least 2 2 elements. Now, let's calculate number of occurrences of each number n u m num in t t and define it as o c c ( n u m ) occ(num). Then t t is dominated (by v v) if (and only if) o c c ( v ) > o c c ( v ′ ) occ(v)>occ(v′) for any other number v ′ v′. For example, arrays [ 1 , 2 , 3 , 4 , 5 , 2 ] [1,2,3,4,5,2], [ 11 , 11 ] [11,11] and [ 3 , 2 , 3 , 2 , 3 ] [3,2,3,2,3] are dominated (by 2 2, 11 11 and 3 3 respectevitely) but arrays [ 3 ] [3], [ 1 , 2 ] [1,2] and [ 3 , 3 , 2 , 2 , 1 ]

Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick

我与影子孤独终老i 提交于 2019-12-04 12:29:05
Recently Petya walked in the forest and found a magic stick. Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number a a is even, then the spell will turn it into 3 a 2 3a2; If the chosen number a a is greater than one, then the spell will turn it into a − 1 a−1. Note that if the number is even and greater than one, then Petya can choose which spell to apply. Petya now has only one number x x. He wants to know if his favorite number y y can be obtained from x x