T1

模拟,80?

#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;
typedef long long LL;
const int N=1e5+;
int a[N],n,len;
char s[N];
int w[N],maxn;
LL f[N],tot;
int main()
{
freopen("maximum.in","r",stdin);
freopen("maximum.out","w",stdout);
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
cin>>(s+);
for(int i=;i<=n;i++)
{
w[i]=s[i]-'';
if(w[i]) maxn=i;
}
for(int i=;i<=maxn;i++)
{
f[i]=f[i-];
if(a[i]>) f[i]+=a[i];
}
w[]=;tot=;
while(maxn>=)
if(w[maxn])
{
if(a[maxn]<=)
{
cout<<(f[maxn-]+tot)<<endl;
return ;
}
tot+=a[maxn];
while(!w[maxn-]) maxn--;
maxn--;
}
cout<<tot<<endl;
return ;
}

first 80

#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;
typedef long long LL;
const int N=1e5+;
int a[N],n,len;
char s[N];
int w[N],maxn;
LL f[N],tot=,ans=;
int main()
{
freopen("maximum.in","r",stdin);
freopen("maximum.out","w",stdout);
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
cin>>(s+);
for(int i=;i<=n;i++)
{
w[i]=s[i]-'';
if(w[i]) maxn=i;
}
f[]=;
for(int i=;i<=maxn;i++)
{
f[i]=f[i-];
if(a[i]>) f[i]+=a[i];
}
w[]=;tot=;
for(int i=maxn;i>=1;i--)
if(w[i])
{
// printf("%lld %lld\n",i,tot+f[i-1]);
ans=max(ans,tot+f[i-1]);
tot+=a[i];
}
cout<<ans<<endl;
return ;
}
w[]=;tot=;LL all=f[maxn];
while(maxn>=)
{
if(a[maxn]<=)
{
cout<<(f[maxn-]+tot)<<endl;
return ;
}
tot+=a[maxn];
while(!w[maxn-]) maxn--;
maxn--;
}

调了半天,我终于发现了错误所在。

说实话:我错的真不怨,我感觉很高兴,因为我找到了自己的思维误区。

怎么说呢:最大值可能出现在这些情况中的任意一个:

        1除了最高位对应的数外,其他任意位上数的组合。(最高位是0)

        2第二高的为0,其他的任意位上的数的组合。(最高位是1)

        3第三高的为0,其他位上任意数的组合。(前两高的是1)

        ............   这道题中的 最高位 是指 m的二进制位为1的。

做的时候还不如取个max那,我只是想当然的认为:

  当最高位是是负数时,前面的一定比后面的要更优。(这是对的,但是)

  我却认为这时,不加这个最高位的负数的结果是最优的。

其实不然,这时,对于不加这位的结果前面都算过,这一次却不一定是最优的!!!!!!

T2

二分+dp

奇怪的贪心。

#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;
const int N=;
int a[N],b[N];
int n,k;
int L,R,mid,ans;
bool check(int x)
{
int sum=,sum0=1e9+;
for(int i=;i<=n;i++)
a[i]=b[i];
a[n+]=a[n];
for(int i=;i<=n;i++)
{
if(abs(a[i]-a[i-])>x)
{
if(a[i]>a[i-])
{
a[i]=a[i-]+x;
sum++;
}else
if(a[i-]>a[i])
{
a[i]=a[i-]-x;
sum++;
}
}
}
int i=,j=n;
for(int i=;i<=n;i++,j--)
a[i]=b[j];
a[n+]=a[n];
for(int i=;i<=n;i++)
{
if(abs(a[i]-a[i-])>x)
{
if(a[i]>a[i-])
{
a[i]=a[i-]+x;
sum0++;
}else
if(a[i-]>a[i])
{
a[i]=a[i-]-x;
sum0++;
}
}
}
sum=min(sum,sum0);
return sum<=k;
}
int main()
{
freopen("minimum.in","r",stdin);
freopen("minimum.out","w",stdout);
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)
{
scanf("%d",&b[i]);
R=max(R,b[i]);
}
if(k>=n-)
{
cout<<<<'\n';
return ;
}
L=,R;
while(L<=R)
{
mid=(L+R)/;
if(check(mid)) R=mid-,ans=mid;
else L=mid+;
}
cout<<ans<<'\n';
return ;
}

first 30

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
int n,k;
int a[],f[];
int L,R,mid;
bool check(int x)
{
f[]=;
int ans=n;//最大不超过n
for(int i=;i<=n;i++)
{
f[i]=i;
for(int j=;j<i;j++)
if(abs(a[i]-a[j])<=(1LL*x*(i-j)))
f[i]=min(f[i],f[j]+(i-j-));
ans=min(ans,f[i]+n-i);
}
return ans<=k;
}
int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
L=,R=1e9+;
while(L<R-)
{
mid=(L+R)>>;
if(check(mid)) R=mid;
else L=mid;
}
if(check(L)) printf("%d\n",L);
else printf("%d\n",R);
return ;
}

二分+dp判断

T3

#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;
const int N=1e3+;
char s[N];
int n,x,y,len;
int q,l,r;
int A[N],B[N];
bool ok[N][N];
int main()
{
freopen("sequence.in","r",stdin);
freopen("sequence.out","w",stdout);
scanf("%d%d%d",&n,&x,&y);
cin>>(s+);
for(int i=;i<=n;i++)
{
A[i]=A[i-];B[i]=B[i-];
if(s[i]=='A') A[i]++;
else B[i]++;
}
for(int i=;i<=n;i++)
for(int j=i;j<=n;j++)
{
int Asum,Bsum;
Asum=A[j]-A[i-];Bsum=B[j]-B[i-];
if(1LL*Asum*y==1LL*Bsum*x) ok[i][j]=;
} scanf("%d",&q);
while(q--)
{
scanf("%d%d",&l,&r);
int L=r-l+;
for(L;L>=;L--)
for(int i=l;i+L-<=r;i++)
if(ok[i][i+L-])
{
printf("%d\n",L);
L=,i=r+;break;
}
}
return ;
}

first

待续。。。。。。

1用和为0,判断,链表查询,O( n q)。

2分块。

3可持久线段树。。。难写。

最短 函数线段树

Day6 下(的更多相关文章

  1. Linux:Day6(下) vim编辑器

    vim编辑器 简介: vi:Visual Interface,文本编辑器 文本:ASCII,Unicode 文本编辑种类: 行编辑器:sed 全屏编辑器:nano,vi VIM - Vi IMprov ...

  2. 清北考前刷题day6下午好

    /* 贪心 负数一定不取 枚举最高位是1 且答案取为0的 位置, 更新答案. */ #include<iostream> #include<cstdio> #include&l ...

  3. day--6_python常用模块

    常用模块: time和datetime shutil模块 radom string shelve模块 xml处理 configparser处理 hashlib subprocess logging模块 ...

  4. Python函数-导入模块的顺序及原理

    引入 当python导入模块,执行import语句时,到底进行了什么操作?按照python的文档,她执行了如下的操作: 第一步,创建一个新的module对象(它可能包含多个module) 第二步,把这 ...

  5. C++程序结构---1

    C++ 基础教程Beta 版 原作:Juan Soulié 翻译:Jing Xu (aqua) 英文原版 本教程根据Juan Soulie的英文版C++教程翻译并改编. 本版为最新校对版,尚未定稿.如 ...

  6. day6、Linux下如何找出7天以前的文件删除

    有些时候,由于系统产生的日志文件,使服务器的磁盘空间紧张,所以怎么删除7天以前的日志文件及让系统只保留7天以内的日志文件 方法一 使用命令:find + |xargs + ls 命令方法:find / ...

  7. Python之路,Day6 - Python基础6

    本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shelve xml处理 yaml处理 configpars ...

  8. Python学习记录day6

    title: Python学习记录day6 tags: python author: Chinge Yang date: 2016-12-03 --- Python学习记录day6 @(学习)[pyt ...

  9. pytho day6 <正则表达式、常用模块、反射>

    本节介绍: 一:正则表达式: 正则表达并不是python 独有的.在各个语言里都有该语法的介绍.正则表达是处理字符串的强大的处理工具.拥有自己的独特的 处理方法.和处理引擎.虽然性能没有python ...

随机推荐

  1. new types may not be defined in a return type(c++语言编译错误,处理)

    在写程序的时候,定义类时要在大括号后面加上: class Point{ public: Point(int a,int b); Point(const Point &p); int getx( ...

  2. 洛谷P4360 [CEOI2004]锯木厂选址(斜率优化)

    传送门 我可能根本就没有学过斜率优化…… 我们设$dis[i]$表示第$i$棵树到山脚的距离,$sum[i]$表示$w$的前缀和,$tot$表示所有树运到山脚所需要的花费,$dp[i]$表示将第二个锯 ...

  3. p2p-如何拯救k8s镜像分发的阿喀琉斯之踵?

    K8s的出现为PaaS行业的发展打了一针兴奋剂,Docker+k8s的技术路线已经成为了容器云的主流.尤其针对大流量,大弹性的应用场景来说,k8s将其从繁杂的运维.部署工作中彻底拯救出来.然而事情往往 ...

  4. How to grow up as a BA

    简书 https://www.jianshu.com/p/8f62b5c7fe1b Thoughtworks https://mp.weixin.qq.com/s/n1hGAM2nUoLvkE5xuU ...

  5. kuangbin专题十六 KMP&&扩展KMP HDU1358 Period

    For each prefix of a given string S with N characters (each character has an ASCII code between 97 a ...

  6. 用rc.local工具开机自启动

    对于一些程序来说,无法直接开机自启动.那么我们可以利用开机自启动来执行一些命令,达到开机自启动的效果!!! 下面用tomcat来举个例子 tomcat启动的命令一般是./startup.sh 那么我们 ...

  7. react 中文文档案例七 (温度计)

    const scaleNames = { c: 'Celsius', f: 'Fahrenheit' }; function toCelsius(fahrenheit) { ) * / ; } fun ...

  8. inner join、left join、right join、full join

    A表 a1 b1 c1 01 数学 95 02 语文 90 03 英语 80  B表 a2 b2 01 张三 02 李四 04 王五 SQL语句:select A.*,B.* from A inner ...

  9. 75th LeetCode Weekly Contest Smallest Rotation with Highest Score

    Given an array A, we may rotate it by a non-negative integer K so that the array becomes A[K], A[K+1 ...

  10. tp 查询