Educational Codeforces Round 60 (Rated for Div. 2)
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)的更多相关文章
- 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 ...
- 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 ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
- 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 ...
- 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() ...
- 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 ...
- 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,所以要用到矩阵快速幂优化 ...
- Educational Codeforces Round 60 (Rated for Div. 2) E. Decypher the String
题目大意:这是一道交互题.给你一个长度为n的字符串,这个字符串是经过规则变换的,题目不告诉你变换规则,但是允许你提问3次:每次提问你给出一个长度为n的字符串,程序会返回按变换规则变换后的字符串,提问3 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
随机推荐
- TS学习随笔(五)->函数
这篇文章我们来看一下TS里面的函数 函数声明 在 JavaScript 中,有两种常见的定义函数的方式——函数声明(Function Declaration)和函数表达式(Function Expre ...
- 自然语言处理NLP快速入门
自然语言处理NLP快速入门 https://mp.weixin.qq.com/s/J-vndnycZgwVrSlDCefHZA [导读]自然语言处理已经成为人工智能领域一个重要的分支,它研究能实现人与 ...
- URL中包含url参数,(文件路径作为参数)
用encodeURIComponent方法,把路径放在里面,可以防止斜杠被取消. 以下attachfiles是我的一个文件的绝对路径. window.location.href="${pag ...
- linux下编译protobuf
这里我介绍两种方法,一是直接ccmake配置,二是修改cmake文件下面的CMakeList.txt文件 第一种方法:配置ccmake 1.安装sudo apt-get install cmake-c ...
- 共创力咨询推出《静态代码分析(PCLint)高级实务培训》课程!
[课程背景] C/C++语言的语法非常灵活性,尤其是指针及内存使用,这种灵活性使代码效率比较高,但同时也使得代码编写具有较大的随意性,另外C/C++编译器不进行强制类型检查,也不对数据边界和有效性进行 ...
- Linux 中使用 firewalld
firewalld 是一种动态防火墙管理解决方案.Centos 7 默认使用 firewalld.firewalld 是对 iptables 的一个封装,可以让你更容易地管理 iptables 规则. ...
- mssql sqlserver 指定特定值排在表前面
转自:http://www.maomao365.com/?p=7141 摘要: 下文讲述sql脚本编写中,将 特定值排在最前面的方法分享, 实验环境:sqlserver 2008 R2 例:将数据表中 ...
- CSS盒子模型(Box Model)
一.背景 作为CSS的重点,三大模块之一的盒子模型,这部分无论如何也要精通透彻.在任何一个网页当中,都有自己的布局方式,所谓网页布局方式就是如何把网页里面的文字.图片,很好的排版成美工设计的样式,这时 ...
- Linux内核最新的连续内存分配器(CMA)——避免预留大块内存【转】
在我们使用ARM等嵌入式Linux系统的时候,一个头疼的问题是GPU,Camera,HDMI等都需要预留大量连续内存,这部分内存平时不用,但是一般的做法又必须先预留着.目前,Marek Szyprow ...
- macOS 安装 Java (Homebrew)
macOS 安装多个 Java 版本 Homebrew 是 macOS 下的一个非常好用的包管理工具, caskroom 则是基于 Homebrew 构建的一个强大的应用程序管理器. Homebrew ...