链接

https://arc100.contest.atcoder.jp/

Linear Approximation

题解

把ai减去i后排序, 我们要的b就是排完序后的中位数

Code

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll; ll read(){
ll x=,f=;char c=getchar();
while(c<'' || c>''){if(c=='-')f=-;c=getchar();}
while(c>='' && c<=''){x=x*+c-'';c=getchar();}
return x*f;
} int n;
int a[];
map<int,int> m; int main(){
#ifdef LZT
freopen("in","r",stdin);
#endif
n=read();
for(int i=;i<=n;i++) a[i]=read()-i;
ll ans=;
sort(a+,a+n+);
int mx=a[(n+)/];
for(int i=;i<=n;i++) ans+=abs(a[i]-mx);
printf("%lld\n",ans);
return ;
}

Equal Cut

题解

如果只切一刀,那么很好确定位置

我们预处理出前i个和后i个切一刀的最佳位置

然后枚举中间的一刀的位置 然后前面后面两刀都处理出来了 算一下取最大值就好

Code

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll; ll read(){
ll x=,f=;char c=getchar();
while(c<'' || c>''){if(c=='-')f=-;c=getchar();}
while(c>='' && c<=''){x=x*+c-'';c=getchar();}
return x*f;
} int n;
ll a[];
ll fen1[],fen2[];
pair<ll,ll> s1[],s2[]; int main(){
#ifdef LZT
freopen("in","r",stdin);
#endif
n=read();
for(int i=;i<=n;i++) a[i]=read();
ll pos=,sum=a[],sum2=a[];
for(int i=;i<=n-;i++){
sum2+=a[i];
while(pos<i){
ll nwsum=sum+a[pos+];
//cout<<sum2<<' '<<sum<<' '<<nwsum<<endl;
if(abs(sum2-sum-sum)>abs(sum2-nwsum-nwsum)){
pos++;
sum=nwsum;
}
else break;
}
//cout<<pos<<endl;
if(pos==i) sum-=a[pos],pos--;
fen1[i]=pos;
s1[i].first=sum;
s1[i].second=sum2-sum;
//cout<<i<<' '<<sum<<' '<<sum2-sum<<endl;
}
pos=n,sum=a[n],sum2=a[n];
for(int i=n-;i>;i--){
sum2+=a[i];
while(pos>i){
ll nwsum=sum+a[pos-];
if(abs(sum2-sum-sum)>abs(sum2-nwsum-nwsum)){
pos--;
sum=nwsum;
}
else break;
}
if(pos==i) sum-=a[pos],pos++;
fen2[i]=pos;
s2[i].first=sum;
s2[i].second=sum2-sum;
//cout<<i<<' '<<sum<<' '<<sum2-sum<<endl;
}
ll ans=1e18;
for(int i=;i<=n-;i++){
ll S1=s1[i].first,S2=s1[i].second,S3=s2[i+].first,S4=s2[i+].second;
ans=min(ans,max(max(max(S1,S2),S3),S4)-min(min(min(S1,S2),S3),S4));
}
printf("%lld\n",ans);
return ;
} /*
5
3 2 4 1 2
*/

Or Plus Max

题解

我们要求max Ai+Aj s.t. i or j <=x

可以转化成max Ai+Aj s.t. i or j =x 然后求一个前缀max

转化成max Ai+Aj s.t. i or j ∈ x 然后求一个前缀max

转化成(max Ai s.t. i ∈ x )+ (second_max Ai s.t. i ∈ x)

所以我们需要维护pair<int,int> b[x]表示所有i∈x的最大值和第二大值

所有i∈x => 快速Zeta变换

然后就做完了

Code

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll; ll read(){
ll x=,f=;char c=getchar();
while(c<'' || c>''){if(c=='-')f=-;c=getchar();}
while(c>='' && c<=''){x=x*+c-'';c=getchar();}
return x*f;
} int n;
int a[];
pair<int,int> b[]; void upd(int x,int y){
int num1=b[x].first,num2=b[x].second,num3=b[y].first,num4=b[y].second;
b[x].first=max(num1,num3);
if(num1>num3) b[x].second=max(num2,num3);
else b[x].second=max(num1,num4);
} int main(){
#ifdef LZT
freopen("in","r",stdin);
#endif
n=read();
for(int i=;i<(<<n);i++)
a[i]=read();
for(int i=;i<(<<n);i++)
b[i].first=a[i],b[i].second=-1e9;
for(int k=;k<n;k++){
//cout<<k<<endl;
for(int i=;i<(<<n);i++){
if((i&(<<k))!=) continue;
upd(i|(<<k),i);
//cout<<(i|(1<<k))<<' '<<i<<endl;
}
}/*
for(int i=0;i+1<(1<<n);i++){
upd(i+1,i);
}*/
int lastans=;
for(int i=;i<(<<n);i++){
lastans=max(lastans,b[i].first+b[i].second);
printf("%d\n",lastans);
}
return ;
} /*
2
1 2 3 1
*/

Colorful Sequences

ARC 100的更多相关文章

  1. 【AtCoder】 ARC 100

    link C-Linear Approximation 给出\(N\)个数\(A_1,A_2,...,A_N\) ,求一个数\(d\),最小化\(\sum_{i=1}^N|A_i-(d+i)|\) 把 ...

  2. ARC 100 C - Linear Approximation题解---三分法

    题目链接: https://arc100.contest.atcoder.jp/tasks/arc100_a 分析: 比赛时做这题想到一个瞎搞的方法就是在平均数上下波动一下取最小值,然后大佬yjw学长 ...

  3. canvas对象arc函数的使用-遁地龙卷风

    (-1)写在前面 我用的是chrome49 <canvas id="lol" height="300"></canvas> (1)详细介 ...

  4. HTML5 Canvas arc()函数//////////////////////(转)

    HTML5 Canvas arc()函数   实例 创建一个圆形: var c=document.getElementById("myCanvas"); var ctx=c.get ...

  5. HTML5 Canvas arc()函数

    实例 创建一个圆形: var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d") ...

  6. 超多经典 canvas 实例,动态离子背景、移动炫彩小球、贪吃蛇、坦克大战、是男人就下100层、心形文字等等等

    超多经典 canvas 实例 普及:<canvas> 元素用于在网页上绘制图形.这是一个图形容器,您可以控制其每一像素,必须使用脚本来绘制图形. 注意:IE 8 以及更早的版本不支持 &l ...

  7. arc路径-磊哥

    不然直接设置80 90要转换成弧度比如Math.PI代表180度你就要 80*Math.PI/180190*Math.PI/180<!DOCTYPE html><html>&l ...

  8. 对canvas arc()中counterclockwise参数的一些误解

    一直没有很细心地去研究CanvasRenderingContext2D对象的arc方法,对它的认识比较模糊,导致犯了一些错误,特发此文,以纠正之前的错误理解. arc()方法定义如下: arc() 方 ...

  9. HTML5 arc的例子

    demo.html <!DOCTYPE html> <html lang="zh"> <head> <meta charset=" ...

随机推荐

  1. IE浏览器部分版本不支持background-size属性问题

    background-size是CSS3新增的属性,但是IE8以下还是不支持,可以通过滤镜来实现这样的一个效果 background-size:contain; // 缩小图片来适应元素的尺寸(保持像 ...

  2. 信雅达面试题atoi函数实现

    atoi函数: 功 能: 把字符串转换成整型数. 名字来源:ASCII to integer 的缩写. 原型: int atoi(const char *nptr); 函数说明 参数nptr字符串,如 ...

  3. Linq To Sql进阶系列(六)用object的动态查询与保存log篇

    动态的生成sql语句,根据不同的条件构造不同的where字句,是拼接sql 字符串的好处.而Linq的推出,是为了弥补编程中的 Data != Object 的问题.我们又该如何实现用object的动 ...

  4. LeetCode题解(19)--Remove Nth Node From End of List

    https://leetcode.com/problems/remove-nth-node-from-end-of-list/ 原题: Given a linked list, remove the  ...

  5. STL--map用法

    STL--map用法map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力由于这个特性它完成有可能在我们处理 ...

  6. hadoop的一般端口使用

  7. SHOW PROCESSLIST Syntax

    https://dev.mysql.com/doc/refman/5.7/en/show-processlist.html SHOW PROCESSLIST shows you which threa ...

  8. webservice client setTimeOut

    一:eclipse生成的client,基于axis client_sub.getOptions().setTimeOutInMilliSeconds(1000*60); client_sub表示一个客 ...

  9. (31)java web的hibernate使用-一级缓存,二级缓存

    参考:https://blog.csdn.net/miachen520/article/details/52195832 hibernate自带一级缓存 和 二级缓存 一,一级缓存: 基于Sessio ...

  10. hadoop配置错误总结

    2016-06-02 17:33:04,163 ERROR org.apache.hadoop.yarn.server.resourcemanager.ResourceManager: RECEIVE ...