A. Best Subsegment

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

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

 #include<bits/stdc++.h>
using namespace std;
const int maxn= 1e5+;
int a[maxn];
int main(){
int n;
scanf("%d",&n);
int maxnum=;
for(int i=;i<n;i++)scanf("%d",&a[i]),maxnum=max(maxnum,a[i]);
int ans=;
int temp=;
for(int i=;i<n;i++){
if(maxnum==a[i]&&i+<n&&a[i]==a[i+])temp++;
else ans=max(temp,ans),temp=;
}
printf("%d",ans);
return ;
}

B. Emotes

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

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

 #include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+;
int a[maxn];
int main(){
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
long long ans=;
int first=a[n-],second=a[n-];
ans=1ll*m/(k+)*(1ll*first*k+second);
m%=(k+);
ans+=1ll*m*first;
printf("%I64d\n",ans); return ;
}

C. Magic Ship

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

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

 #include<bits/stdc++.h>
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;i++)
#define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr))
#define F first
#define S second
#define pii pair<int ,int >
#define mkp make_pair
#define pb push_back
using namespace std;
const long long inf=1e18;
typedef long long ll;
const int maxn=1e5+;
map<char,pii>mp;
ll sumx[maxn],sumy[maxn];
char s[maxn];
void init(){
mp['U']={,};mp['D']={,-};mp['L']={-,};mp['R']={,};
}
int n;
ll X1,Y1,X2,Y2;
bool check(ll mid){
ll q=mid/n,r=mid%n;
ll nx=X1+sumx[n]*q+sumx[r];
ll ny=Y1+sumy[n]*q+sumy[r];
return (abs(nx-X2)+abs(ny-Y2))<=mid;
}
int main(){
init();
scanf("%lld%lld%lld%lld",&X1,&Y1,&X2,&Y2);
scanf("%d",&n);
scanf("%s",s+);
FOR(i,,n){
sumy[i]=sumy[i-]+mp[s[i]].S;
sumx[i]=sumx[i-]+mp[s[i]].F;
}
ll l=,r=inf;
ll ans=inf;
while(l<=r){
ll mid=l+r>>;
if(check(mid))ans=mid,r=mid-;
else l=mid+;
}
if(ans!=inf)cout<<ans<<endl;
else cout<<-<<endl; return ;
}

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)

.....

 #include<bits/stdc++.h>
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;i++)
#define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr))
#define F first
#define S second
#define pii pair<int ,int >
#define mkp make_pair
#define pb push_back
using namespace std;
const long long inf=1e18;
typedef long long ll;
const int mod=1e9+;
long long n,m;
struct mat{
ll m[][];
mat(){
MS(m,);
}
};
mat Mul(mat a,mat b,int n){
mat res;
int i,j,k;
for( i=;i<=n;i++){
for( j=;j<=n;j++){
res.m[i][j]=;
for(k=;k<=n;k++){
res.m[i][j]=(res.m[i][j]+(a.m[i][k]*b.m[k][j])%mod+mod)%mod;
}
}
}
return res;
}
mat fpow(mat a,ll b,int n){
mat ans;
for(int i=;i<=n;i++)ans.m[i][i]=;
while(b){
if(b&)ans=Mul(ans,a,n);
a=Mul(a,a,n);
b>>=;
}
return ans;
}
const int maxn=1e5+;
int dp[];
int main(){
scanf("%lld%lld",&n,&m);
if(n<=m){
if(n==m)cout<<<<endl;
else
cout<<<<endl;
return ;
}
dp[]=;
for(int i=;i<m;i++)dp[i]=;
dp[m]=dp[]+dp[m-];
mat d;
d.m[][]=;d.m[][m]=;
for(int i=;i<=m+;i++)d.m[i][i-]=;
mat e;
for(int i=;i<=m+;i++){
e.m[m+-i][]=dp[i-];
}
/* for(int i=1;i<=m+1;i++){
cout<<e.m[i][1]<<endl;
}
for(int i=1;i<=m+1;i++){
for(int j=1;j<=m+1;j++){
cout<<d.m[i][j]<<" ";
}
cout<<endl;
}
*/ d=fpow(d,n-m,m+);
d=Mul(d,e,m+);
cout<<(d.m[][])%mod<<endl; return ;
}

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

  1. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

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

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

  4. 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 ...

  5. 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() ...

  6. Educational Codeforces Round 60 (Rated for Div. 2) 即Codeforces Round 1117 C题 Magic Ship

    time limit per test 2 second memory limit per test 256 megabytes input standard inputoutput standard ...

  7. 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,所以要用到矩阵快速幂优化 ...

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

    题目大意:这是一道交互题.给你一个长度为n的字符串,这个字符串是经过规则变换的,题目不告诉你变换规则,但是允许你提问3次:每次提问你给出一个长度为n的字符串,程序会返回按变换规则变换后的字符串,提问3 ...

  9. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

随机推荐

  1. 通过ADB查看当前Activity

    cmd命令中输入:adb shell dumpsys activity activities 在一连串的输出中找到Runing activities com.android.settings是包名. ...

  2. virtual table for class

    虚函数表 说起虚函数,相信你我都可以自然而然的想到“多态”,因为多态的实现就依赖于虚函数的继承和重写(覆盖).那么,class又或者是object是如何来管理虚函数的呢?你我又会想到虚函数表. 虚函数 ...

  3. 用canvas给视频图片添加特效

    Canvas制作视频图片特效 1. Canvas介绍 1.1Canvas是html5上的一个画布标签,功能有点类似java的swing.可以在canvas上画线条 弧线, 文字 就是画布的功能. 具体 ...

  4. myapp——自动生成小学四则运算题目的命令行程序(侯国鑫 谢嘉帆)

    1.Github项目地址 https://github.com/baiyexing/myapp.git 2.功能要求 题目:实现一个自动生成小学四则运算题目的命令行程序 功能(已全部实现) 使用 -n ...

  5. eclipse开发创建web项目

    1.打开eclipse,界面如下: 2.首先配置tomcat,操作:Windows--->perferences 如下: 3.操作:server--->Runtime Environmen ...

  6. USB初学(一)---USB-HID的初步认识【转】

    HID是一种USB通信协议,无需安装驱动就能进行交互,在学习HID之前,先来复习一下USB协议的相关内容. USB设备描述符-概述 当插入USB设备后,主机会向设备请求各种描述符来识别设备.那什么是设 ...

  7. Jenkins自动化部署-----持续交付【转】

    感谢之前带领过我的leader,让我能够知道什么是好的开发方法. 在很早之前就接触过敏捷开发.什么是敏捷开发,简单来说就是让软件可靠地,快速地发布出来的一种开发方法和技巧. 而敏捷开发中有许多的实践, ...

  8. 【Linux基础】查看硬件信息-内存和硬盘

     1.使用free命令查看内存使用 (1)内存总量大小:查看Mem中的total值3697M free -m total used free shared buffers cached -/+ buf ...

  9. Spring AOP前置通知实例说明AOP相关概念

    今天又看了下韩顺平的SpringAOP的讲解,讲解的很透彻.仿照视频自己使用下前置通知. 一.引出问题 有个接口TestServiceInter,有两个实现方法TestService和Test2Ser ...

  10. 【Swift 3.0】iOS 国际化切换语言

    有的 App 可能有切换语言的选项,结合系统自动切换最简单的办法: fileprivate var localizedBundle: Bundle = { return Bundle(path: Bu ...