Educational Codeforces Round 60 (Rated for Div. 2)

A. Best Subsegment

题意 找 连续区间的平均值  满足最大情况下的最长长度

思路:就是看有几个连续的最大值

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=    1e5+4;
 4 int a[maxn];
 5 int main(){
 6 int n;
 7 scanf("%d",&n);
 8 int maxnum=0;
 9 for(int i=0;i<n;i++)scanf("%d",&a[i]),maxnum=max(maxnum,a[i]);
10 int ans=1;
11 int temp=1;
12 for(int i=0;i<n;i++){
13 if(maxnum==a[i]&&i+1<n&&a[i]==a[i+1])temp++;
14 else ans=max(temp,ans),temp=1;
15 }
16 printf("%d",ans);
17 return 0;
18 }

B. Emotes

题意: n个数字 (正)  每个可以用任意次   一共m次   一个数字不能用超过连续k次  问m次 用的数字的和的最大值是多少

思路:直接找最大和次大  最大k次+次大1次 循环 最后处理一下余数即可

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=2e5+5;
 4 int a[maxn];
 5 int main(){
 6     int  n,m,k;
 7     scanf("%d%d%d",&n,&m,&k);
 8     for(int i=0;i<n;i++){
 9         scanf("%d",&a[i]);
10     }
11     sort(a,a+n);
12     long long ans=0;
13     int first=a[n-1],second=a[n-2];
14     ans=1ll*m/(k+1)*(1ll*first*k+second);
15     m%=(k+1);
16     ans+=1ll*m*first;
17     printf("%I64d\n",ans);
18
19 return 0;
20 }

C. Magic Ship

题意:给出n个风向  风是循环运作的 并且给出起点和终点(二维)问可否到达终点

思路:将x y分解  对风求前缀和 二分找步数  看是否满足题意  这里记得二分范围要大 1e18 不然就会gg(虽然过了 但是我总感觉有点怪怪的好像能出数据hack 可能是有完备性证明的,只是我太菜不会证吧。。)

 1 #include<bits/stdc++.h>
 2 #define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;i++)
 3 #define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr))
 4 #define F first
 5 #define S second
 6 #define pii pair<int ,int >
 7 #define mkp make_pair
 8 #define pb push_back
 9 using namespace std;
10 const long long  inf=1e18;
11 typedef long long ll;
12 const int maxn=1e5+6;
13 map<char,pii>mp;
14 ll sumx[maxn],sumy[maxn];
15 char s[maxn];
16 void init(){
17     mp[‘U‘]={0,1};mp[‘D‘]={0,-1};mp[‘L‘]={-1,0};mp[‘R‘]={1,0};
18 }
19 int n;
20 ll X1,Y1,X2,Y2;
21 bool check(ll mid){
22 ll q=mid/n,r=mid%n;
23 ll nx=X1+sumx[n]*q+sumx[r];
24 ll ny=Y1+sumy[n]*q+sumy[r];
25 return (abs(nx-X2)+abs(ny-Y2))<=mid;
26 }
27 int main(){
28     init();
29     scanf("%lld%lld%lld%lld",&X1,&Y1,&X2,&Y2);
30     scanf("%d",&n);
31     scanf("%s",s+1);
32     FOR(i,1,n){
33         sumy[i]=sumy[i-1]+mp[s[i]].S;
34         sumx[i]=sumx[i-1]+mp[s[i]].F;
35     }
36     ll l=0,r=inf;
37     ll ans=inf;
38     while(l<=r){
39         ll mid=l+r>>1;
40         if(check(mid))ans=mid,r=mid-1;
41         else l=mid+1;
42     }
43     if(ans!=inf)cout<<ans<<endl;
44     else cout<<-1<<endl;
45
46
47 return 0;
48 }

D. Magic Gems

题意  一个特殊基因可以分成m个普通基因  问刚好n个基因有多少种组成方式   1<=n<=1e18  2<=m<=100

思路:看这数据范围 这题目就一股浓浓的矩阵快速幂的味道  直接列出转移式 构造矩阵  dp[n]=dp[n-1]+dp[n-m];

(1....10) 大概就这意思吧 然后直接套矩阵就行了   (写的时候傻逼用int读long long) m*m的矩阵

(1.......0)
(01......0)

(001......0)

.....

 1 #include<bits/stdc++.h>
 2 #define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;i++)
 3 #define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr))
 4 #define F first
 5 #define S second
 6 #define pii pair<int ,int >
 7 #define mkp make_pair
 8 #define pb push_back
 9 using namespace std;
10 const long long  inf=1e18;
11 typedef long long ll;
12 const int mod=1e9+7;
13 long long  n,m;
14 struct mat{
15 ll m[105][105];
16     mat(){
17         MS(m,0);
18     }
19 };
20 mat Mul(mat a,mat b,int n){
21     mat res;
22     int i,j,k;
23     for( i=1;i<=n;i++){
24         for( j=1;j<=n;j++){
25             res.m[i][j]=0;
26             for(k=1;k<=n;k++){
27                 res.m[i][j]=(res.m[i][j]+(a.m[i][k]*b.m[k][j])%mod+mod)%mod;
28             }
29         }
30     }
31     return res;
32 }
33 mat fpow(mat a,ll b,int n){
34     mat ans;
35     for(int i=1;i<=n;i++)ans.m[i][i]=1;
36     while(b){
37         if(b&1)ans=Mul(ans,a,n);
38         a=Mul(a,a,n);
39         b>>=1;
40     }
41     return ans;
42 }
43 const int maxn=1e5+6;
44 int dp[200];
45 int main(){
46     scanf("%lld%lld",&n,&m);
47     if(n<=m){
48         if(n==m)cout<<2<<endl;
49         else
50         cout<<1<<endl;
51         return 0;
52     }
53     dp[0]=1;
54   for(int i=1;i<m;i++)dp[i]=1;
55   dp[m]=dp[0]+dp[m-1];
56     mat d;
57     d.m[1][1]=1;d.m[1][m]=1;
58     for(int i=2;i<=m+1;i++)d.m[i][i-1]=1;
59     mat e;
60     for(int i=1;i<=m+1;i++){
61         e.m[m+2-i][1]=dp[i-1];
62     }
63   /*  for(int i=1;i<=m+1;i++){
64         cout<<e.m[i][1]<<endl;
65     }
66    for(int i=1;i<=m+1;i++){
67         for(int j=1;j<=m+1;j++){
68             cout<<d.m[i][j]<<" ";
69         }
70         cout<<endl;
71     }
72 */
73
74     d=fpow(d,n-m,m+1);
75     d=Mul(d,e,m+1);
76     cout<<(d.m[1][1])%mod<<endl;
77
78     return 0;
79 }

原文地址:https://www.cnblogs.com/ttttttttrx/p/10604737.html

时间: 2024-08-30 17:39:59

Educational Codeforces Round 60 (Rated for Div. 2)的相关文章

Educational Codeforces Round 60 (Rated for Div. 2) E. Decypher the String

题目大意:这是一道交互题.给你一个长度为n的字符串,这个字符串是经过规则变换的,题目不告诉你变换规则,但是允许你提问3次:每次提问你给出一个长度为n的字符串,程序会返回按变换规则变换后的字符串,提问3次后你需要猜出这个字符串.解法是学习https://blog.csdn.net/baiyifeifei/article/details/87807822 这个博主的,借用了进制的思想非常巧妙. 解法:对于某个位置的来源位置我们设为x,因为26*26*26>10000,那么x可以唯一表示为x=a*26

Educational Codeforces Round 60 (Rated for Div. 2) A. Best Subsegment

time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given array a 1 , a 2 ,-, a n a1,a2,-,an . Find the subsegment a l , a l+1 ,-, a r al,al+1,-,ar ( 1≤l≤r≤n 1≤l≤r≤n ) with maximum arithmet

Educational Codeforces Round 60 (Rated for Div. 2) D. Magic Gems(矩阵快速幂)

题目传送门 题意: 一个魔法水晶可以分裂成m个水晶,求放满n个水晶的方案数(mol1e9+7) 思路: 线性dp,dp[i]=dp[i]+dp[i-m]; 由于n到1e18,所以要用到矩阵快速幂优化 注意初始化 代码: #include<bits/stdc++.h> using namespace std; #define mod 1000000007 typedef long long ll; #define MAX 105 const int N=105;//矩阵的大小 int T; ll

Educational Codeforces Round 60 (Rated for Div. 2)E(思维,哈希,字符串,交互)

#include <bits/stdc++.h>using namespace std;int main(){ string t; cin>>t; int n=t.size(); string s1(n,'a'),s2(n,'a'),s3(n,'a'); for(int i=0;i<n;i++){  s1[i]=char('a'+(i%26));//从a到z循环  s2[i]=char('a'+((i/26)%26));//第i位为(i/26)%26+'a',保证了26*26

Educational Codeforces Round 60 (Rated for Div. 2)D(思维,DP,快速幂)

#include <bits/stdc++.h>using namespace std;const long long mod = 1e9+7;unordered_map<long long,long long>mp;long long n,m;long long dp(long long n){    if(n<0)        return 0;    if(n<m)        return 1;    if(mp.find(n)!=mp.end())//已经

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

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

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

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

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.