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< ...
随机推荐
- 在Office应用中打开WPF窗体并且让子窗体显示在Office应用上
在.NET主程序中,我们可以通过创建 ExcelApplication 对象来打开一个Excel应用程序,如果我们想在Excle里面再打开WPF窗口,问题就不那么简单了. 我们可以简单的实例化一个WP ...
- 一个表里有多个字段需要同时使用字典表进行关联显示,如何写sql查询语句
参考:https://bbs.csdn.net/topics/330032307 数据库里面有一个字典表,这张表里面有id段和对应的名字字段.在另外一个记录的表里面有对应的上述字典表的id,而且有多个 ...
- FIDDLER的使用方法及技巧总结
转自: https://www.cnblogs.com/ink-marks/p/6363275.html 一.FIDDLER快速入门及使用场景 Fiddler的官方网站:http://www.fidd ...
- SQL Server 索引碎片产生原理重建索引和重新组织索引
数据库存储本身是无序的,建立了聚集索引,会按照聚集索引物理顺序存入硬盘.既键值的逻辑顺序决定了表中相应行的物理顺序 多数情况下,数据库读取频率远高于写入频率,索引的存在 为了读取速度牺牲写入速度 页 ...
- oracle 10g函数大全--日期型函数
sysdate [功能]:返回当前日期. [参数]:没有参数,没有括号 [返回]:日期 [示例]select sysdate hz from dual; 返回:2008-11-5 add_months ...
- DRF项目创建流程(1)
一 web应用模式 前后端不分离 前后端分离 二 RESTFUL API规范 REST全称是Representational State Transfer,中文意思是表述(编者注:通常译为表征)性状态 ...
- Java 通过地址获取经纬度 - 高德地图
一.添加依赖 <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-v ...
- 20 python 初学(logging模块)
学习网站:https://www.cnblogs.com/yuanchenqi/articles/5732581.html logging 模块: # _author: lily # _date: 2 ...
- Jenkins + Ansible + Gitlab之ansible篇
Ansible介绍 什么是Ansible? Ansible是一个开源部署工具 开发语言:Python 特点:SSH协议通信,全平台,无需要编译,模块化部署管理 作用:推送Playbook进行远程节点快 ...
- mysql中group by和order by混用 结果不是理想结果(转)
文章转自 https://www.cnblogs.com/myphper/p/3767572.html 在使用mysql排序的时候会想到按照降序分组来获得一组数据,而使用order by往往得到的不是 ...