rated

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

邮差的信 提交于 2019-12-04 11:49:16
D. Yet Another Monster Killing Problem You play a computer game. In this game, you lead a party of 𝑚 heroes, and you have to clear a dungeon with 𝑛 monsters. Each monster is characterized by its power 𝑎𝑖. Each hero is characterized by his power 𝑝𝑖 and endurance 𝑠𝑖. 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 𝑘 monsters, the hero

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

試著忘記壹切 提交于 2019-12-04 11:40:45
C. Dominated Subarray Let's call an array 𝑡 dominated by value 𝑣 in the next situation. At first, array 𝑡 should have at least 2 elements. Now, let's calculate number of occurrences of each number 𝑛𝑢𝑚 in 𝑡 and define it as 𝑜𝑐𝑐(𝑛𝑢𝑚). Then 𝑡 is dominated (by 𝑣) if (and only if) 𝑜𝑐𝑐(𝑣)>𝑜𝑐𝑐(𝑣′) for any other number 𝑣′. For example, arrays [1,2,3,4,5,2], [11,11] and [3,2,3,2,3] are dominated (by 2, 11 and 3 respectevitely) but arrays [3], [1,2] and [3,3,2,2,1] are not. Small remark: since any array can be dominated only by one number, we can not specify this number and just say that array is either

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

匆匆过客 提交于 2019-12-04 11:38:30
A. Two Rival Students There are 𝑛 students in the row. And there are two rivalling students among them. The first one is in position 𝑎, the second in position 𝑏. Positions are numbered from 1 to 𝑛 from left to right. Since they are rivals, you want to maximize the distance between them. If students are in positions 𝑝 and 𝑠 respectively, then distance between them is |𝑝−𝑠|. You can do the following operation at most 𝑥 times: choose two adjacent (neighbouring) students and swap them. Calculate the maximum distance between two rivalling students after at most 𝑥 swaps. Input The first line

Educational Codeforces Round 76 (Rated for Div. 2)

人走茶凉 提交于 2019-12-04 10:53:56
题意: 给你n个关卡,每个关卡有一个怪物,怪物的攻击力为a【i】,你有n个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打好几关(只要在疲劳范围内),打不过的话英雄就结束今天的挑战,转到第二天。问最少需要出战多少英雄才能通过所有关卡。 思路:先用一个数组。跑出相同忍耐值时,攻击力越大。然后·跑出这个数组的后缀pre数组,pre数组的含义是:忍耐值一定,攻击力最大。然后通过O(n)的复杂度跑·怪物的数组。当怪物的a【i】值大于pre数组在上一天的攻击力时,进入下一天。【变相的二分】【题目比较难叙述QAQ】 代码: 1 #include<bits/stdc++.h> 2 3 using namespace std; 4 5 #define int long long 6 const int N=22e4;int n; 7 int arr[N]; 8 int pre[N]; 9 int str[N]; 10 int slove(){ 11 int ans=1;//总天数 12 int last_time=-1; 13 int maxn=0; 14 for(int i=0;i<n;i++){ 15 maxn=max(maxn,arr[i]); 16 if(pre[i-last_time]<maxn){ 17

Educational Codeforces Round 76 (Rated for Div. 2)

一世执手 提交于 2019-12-04 10:48:47
第三道签到题没做出来,卡在读错题意和一个简单的逻辑bug,哭死 A题: 答案= |a-b|+x >n-1 ? n-1 : |a-b|+x 刚开始我竟想到取模,wsl。 #include<bits/stdc++.h> using namespace std; int main() { int t; scanf("%d",&t); int n,x,a,b; while(t--){ scanf("%d%d%d%d",&n,&x,&a,&b); if(abs(a-b)==n-1){ printf("%d\n",n-1); continue; } int ans=(abs(a-b)+x); ans=ans>n-1?n-1:ans; printf("%d\n",ans); } return 0; } B题: 直接特判,2和3比较特殊,2/2*3=3,(3-1)/2*3=3。 x>=y肯定可以,x只要不断减1 。 x<y,特判1,2,3,其余都是可以的,其他数字都可以经过 除2乘3不断 递增。 #include<bits/stdc++.h> using namespace std; int main() { int t; scanf("%d",&t); while(t--){ int x,y; scanf("%d%d",&x,&y); if(y<=x){ puts("YES"); } else

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

余生长醉 提交于 2019-12-04 10:40:05
Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以把数字移动给别人,问最少移动几次后可以使第一个人的数字为1~m1,第二个人m1~m2,第三个人m2~n(可以没有数字) 题解: 设c[1][i]为第一个人m1为i时需要移动的次数,c[3][i]为m2为i是第三个人需要操作的次数,当其他两个人数字合法时,第二个人的数字也会合法.枚举第一个人的每个i,查询m2为(i+1~n+1)的最小操作次数,ans = min{c[1][i]+min(c[3][k](i<k<=n))} 查询操作可用线段树维护 代码: #include <bits/stdc++.h> using namespace std; const int N = 250000; int t[4*N],a[5][N],b[5][N],c[5][N]; void build(int x,int l,int r) { if (l == r) { t[x] = c[3][l]; return; } int mid = (l + r) >>1; build(x<<1,l,mid); build(x<<1|1,mid+1,r); t[x] = min(t[x<<1] , t[x<<1|1])

Educational Codeforces Round 76 (Rated for Div. 2)

百般思念 提交于 2019-12-04 10:25:06
A - Two Rival Students 题意:共n个人排一排,两个人,位于a,b,相邻位置交换至多x次,最大化abs(a-b)的值。 题解:每次交换至多+1,不能超过n-1。 #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { #ifdef KisekiPurin freopen("KisekiPurin.in", "r", stdin); #endif // KisekiPurin int t; scanf("%d", &t); while(t--) { int n, x, a, b; scanf("%d%d%d%d", &n, &x, &a, &b); printf("%d\n", min(n - 1, abs(a - b) + x)); } return 0; } B - Magic Stick 题意:给一个数a,有无限次的两种操作:1、若a是偶数,则加上a的一半。2、若a>1,则减去1。问是否可以从x构造出y。 题解:有无限次减法,就看1操作能到达哪里就可以。首先1是不能动的,y<=1。其次,2可以到3,3可以到2,没办法突破到4,所以x=2或x=3时,y<=3。而4可以有4->6->9->8->12->18->27->26->39->...这样无限做下去

Educational Codeforces Round 67 (Rated for Div. 2) B题【前缀+二分】【补题ING系列】

守給你的承諾、 提交于 2019-12-04 06:17:59
题意:给出一个字符串s, 可以从左往右拿走s的字符, 至少要到s的第几个位置才能拼成t 思路:用二维数组记录前缀,然后二分即可. 1 #include<bits/stdc++.h> 2 3 using namespace std; 4 #define inf 5000000 5 #define N 210050 6 int sum[N][30]; 7 int arr[30]; 8 string s; 9 string str; 10 int n; 11 bool slove(int id) { 12 for(int i=0; i<26; i++) 13 if(arr[i]-sum[id][i]>0) 14 return false; 15 return true; 16 } 17 int main() { 18 cin>>n; 19 cin>>str; 20 int _; 21 cin>>_; 22 for(int i=0; i<str.size(); i++) { 23 ++sum[i][str[i]-'a']; 24 if(i!=0) { 25 for(int j=0; j<26; j++) { 26 sum[i][j]+=sum[i-1][j]; 27 } 28 } 29 } 30 while(_--) { 31 cin>>s; 32 for(int i=0; i<=26;

Educational Codeforces Round 75 (Rated for Div. 2)D(二分)

孤街醉人 提交于 2019-12-04 05:00:57
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; pair<int,int>a[200007]; int n; long long s; bool check(int x){ int num=0; long long sum=s; for(int i=n;i;--i){ if(a[i].first>=x) ++num; else if(a[i].second>=x&&sum>=x-a[i].first){ ++num; sum-=x-a[i].first; } } if(num>=n/2+1) return 1; return 0; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin>>t; while(t--){ cin>>n>>s; int x,y; for(int i=1;i<=n;++i){ cin>>x>>y; a[i]={x,y}; s-=x; } sort(a+1,a+1+n); int l=a[n/2+1].first,r=1e9; int ans=0; while(l<=r){ int mid=(l+r)>>1; if(check(mid)){ ans

Educational Codeforces Round 73 (Rated for Div. 2)

爱⌒轻易说出口 提交于 2019-12-03 15:06:28
Educational Codeforces Round 73 (Rated for Div. 2) A. 2048 Game 思路:水题 AC代码 #include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> typedef long long ll; typedef unsigned long long ull; using namespace std; ll mult_mod(ll x, ll y, ll mod){ return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod; } ll pow_mod(ll a, ll b, ll p){ ll res = 1; while (b){ if (b & 1) res = mult_mod(res, a, p); a = mult_mod(a, a, p); b >>= 1;