HDU 4379 The More The Better
来源:互联网 发布:centos ftp指定目录 编辑:程序博客网 时间:2024/06/07 18:36
真是个奇葩的题目!卡了N次。
1.并不一定是连续的子串,这个题相当于从n个数中挑出符合条件的数。
2.很容易超时,我超时的原因是用了 maxx=max(maxx,num);而换成 maxx=maxx>num?maxx:num;就不会超时。
3.思路:找出的子串中任意的两个相加都<=L,那么子串中最多有一个数超过L,方法就是求出所有<=L/2的数的个数,并且记录下<=L/2的数中最大的,即maxx,以及>L/2的数中最小的一个即minn,最后如果minn+maxx<=L,答案加1.
4.如果 maxx=-0xffffff; minn=0xffffff;这样初始化会是WA。(因为0xffffff是16777215,0x7fffffff=2147483647)
5.关于minn和maxx初始化,一开始以为minn初始化为mod大小就可以了,但是如果整个长度为n序列中所有的长度都小于 L/2,也就是说在这条 if(mina+maxa<=l) 语句中mina的值就是初始值,加入初始值是mod的话 那么 mina+maxa=mod+maxa可能会小于L从而执行 sum++,可此时是没有大于L/2的元素的。所以可以初始化为minn=L+2;maxx=-1;
AC代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int main(){ // freopen("in.txt","r",stdin); long long int n,L,a,b,mod,ans,num,maxx,minn; while(cin>>n>>L>>a>>b>>mod) { ans=0; maxx=-2000000000; minn=1100000000000; // maxx=-0xffffff; //WA // minn=0xffffff; //WA for(long long int i=1; i<=n; i++) { num=(a*i+b)%mod; if(num<=L/2) { ans++; //maxx=max(maxx,num);//这样写会TLE maxx=maxx>num?maxx:num; } else //minn=min(minn,num);//这样写会TLE minn=minn<num?minn:num; } if(maxx+minn<=L) ans++; cout<<ans<<endl; } return 0;}
- HDU 4379 - The More The Better
- [统计] hdu 4379 the more the better
- hdu 4379 The More The Better
- HDU 4379 The More The Better
- HDU:4379 The More The Better
- hdu 4379The More The Better
- hdu-The more, The Better
- hdu The more, The Better
- hdu The more, The Better
- The more, The Better HDU
- The more, The Better HDU
- hdu——4379 ——The More The Better
- BNU OJ The More The Better || HDU 4379
- HDU 4379 The More The Better [坑爹想法题]
- hdoj(hdu)-1561-the more the better
- hdu 1561 The more,The better
- HDU 1516 The more, The Better
- hdu 1561 the more,the better
- Windchill 10.0 开发环境配置
- hdu 3316 Mine sweeping(迷宫)
- webshell之复杂版本jsp
- Android 异步操作AsyncTask
- HDU 1009 Fatmouse’s trade
- HDU 4379 The More The Better
- Android设置定时执行执行一次任务
- android AsyncTask 详细例子
- Myeclipse 性能优化
- android AsyncTask 详细例子(2)
- LAMP--系统、平台、数据库和程序
- 命令行形式下的Qt实现编译连接
- HDU 1050 moving table
- 解决如何让AsyncTask终止操作