UVALive 6886 Golf Bot 桶排+剪枝
来源:互联网 发布:采购软件视频 编辑:程序博客网 时间:2024/05/16 12:10
这是一道限时15000ms的题,然后我卡了五发超时和RE。
要注意给的dj<=200000
tho: 刚写时的思路就是将机器人可以打出的距离组合后桶排存起来, 但是各种小优化后发现还是T。
最后看出在将机器人打出的距离组合前先从小到达排序,然后在组合时大于200000时跳出即可。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[201234], b[201234];int main(){ int n, m; while(scanf("%d",&n)!=EOF) { int book[200004]= {0}; int o=0; for(int i=0; i<n; i++) { scanf("%d",&a[i]); book[a[i]]=1; int x = a[i]<<1; if( x<= 200000) book[x]=1; } sort(a,a+n); for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { int t=a[i]+a[j]; if(t<=200000) { book[t]=1; } else break;//这个break助你AC。。。 } } scanf("%d",&m); int ans=0; for(int i=0; i<m; i++) { int x; scanf("%d",&x); if(book[x]) ans++; } printf("%d\n",ans); } return 0;}
阅读全文
0 0
- UVALive 6886 Golf Bot 桶排+剪枝
- UVALive 6886 Golf Bot
- 【暴力预处理+剪枝/bitset】Golf Bot UVALive
- UVALive 6886 Golf Bot FFT
- UVALive 6886 (LA 6886) Golf Bot FFT
- UVALive 6886 Golf Bot(FFT)
- UVALive 6886 Golf Bot (FFT)
- 6886 - Golf Bot
- HNU11376:Golf Bot
- UVALive6886 Golf Bot[FFT]
- UVALive 6835 - Space Golf
- UVALive 6835 - Space Golf
- UVALive 6835 Space Golf(物理题)
- UVALive 6835Space Golf-计算几何
- UVALive 6835 - Space Golf(简单解析几何)
- Golf
- UVALive 6432 Influence 搜索 剪枝
- UVALive 4527 Vaccination Centers 搜索+剪枝
- 如何在CSDN博客中的所贴的代码进行【代码块】显示
- 【POJ 3468 A Simple Problem with Integers】 线段树
- 杂谈
- poj 2566 Bound Found 尺取法 / lower_bound
- Django建教育平台(六)--首页和登录页面配置
- UVALive 6886 Golf Bot 桶排+剪枝
- CentOS 使用yum命令安装出现错误提示:Loaded plugins: fastestmirror, refresh-packagekit, security
- SpringBoot环境搭建eclipse版和IntelliJ IDEA版
- 各种排序
- 最大流增广路
- luoguP2831 愤怒的小鸟
- 数据预处理之特征选择
- 鸟叔Linux学习笔记:第一章 Linux是什么与如何学习
- 使用Java网络编程创建基于UDP协议的Server和Client