啊希吧!第一场队内赛总结
来源:互联网 发布:张大奕有几个淘宝店 编辑:程序博客网 时间:2024/05/21 04:39
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">今天学长讲完二分法打了一场队内赛,</span>
6道题目截止到刚才AC了5道,
还有一道真的不会 = =
讲一下总结
其实rank可以更高
B题换了个double就过了
之前无限WA。。。
然后,A题二分写cuo了= =
然后强烈的感觉就是自己真的是弱渣,
可以随便被虐的那种 = =
时间复杂度这个东西知道有一年多了
然而真的有直观的感受还是今天= =
于是我就拿A题出来说一下子。
Description
Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate if you can find the three numbers Ai, Bj, Ck, which satisfy the formula Ai+Bj+Ck = X.
Input
There are many cases. Every data case is described as followed: In the first line there are three integers L, N, M, in the second line there are L integers represent the sequence A, in the third line there are N integers represent the sequences B, in the forth line there are M integers represent the sequence C. In the fifth line there is an integer S represents there are S integers X to be calculated. 1<=L, N, M<=500, 1<=S<=1000. all the integers are 32-integers.
Output
For each case, firstly you have to print the case number as the form "Case d:", then for the S queries, you calculate if the formula can be satisfied or not. If satisfied, you print "YES", otherwise print "NO".
Sample Input
3 3 31 2 31 2 31 2 331410
Sample Output
Case 1:NOYESNO
三个序列开的大小分别是 500 500 500 和序列开的是1000
相乘的话 就是125*10^9
1s大概是 10^8的样子
暴力肯定TLE
于是想到一种方法
A B所有的相加情况变成一个序列E
然后和序列D减去另一个序列C
再在E序列中去查找
这样的话
时间复杂度就变成了
log(500*500)*500*1000
直接降了好几个数量级
嗯 然后二分查找的模板还是要记清楚的
比如是low>=high
最后贴代码
#include <stdio.h>#include <algorithm>using namespace std;#define maxn 1001int a[maxn],b[maxn],c[maxn],x[maxn],d[maxn*maxn];int icq(int a[],int n,int key){ int low=0; int high=n-1; int mid; while(low<=high) { mid=(low+high)/2; if(a[mid]<key) { low=mid+1; } else if(a[mid]>key) { high=mid-1; } else if(a[mid]==key) return 1; } return -1;}int main(){ int d0,m,n,s,i,j,k,l,flag; d0=0; while(scanf("%d %d %d",&l,&m,&n)!=EOF) { d0++; for(i=0; i<l; i++) scanf("%d",&a[i]); for(i=0; i<m; i++) scanf("%d",&b[i]); for(i=0; i<n; i++) scanf("%d",&c[i]); scanf("%d",&s); for(i=0; i<s; i++) scanf("%d",&x[i]); printf("Case %d:\n",d0); k=0; for(i=0; i<l; i++) for(j=0; j<m; j++) { d[k]=a[i]+b[j]; ++k; } sort(d,d+k); for(j=0; j<s; j++) { flag=0; i=0; for(i=0; i<n; i++) { l=x[j]-c[i]; if(icq(d,k,l)==1) { printf("YES\n"); flag=1; break; } } if(flag==0)printf("NO\n"); } } return 0;}
0 0
- 啊希吧!第一场队内赛总结
- Struts第一个总结
- 第一个项目总结
- 第一个项目总结
- 第一张总结
- 大二第一学期总结
- JAVA第一课总结
- 集训队第一期总结
- 第一个七天总结
- acm第一赛季总结
- 大三第一学期总结
- 第一场总结
- 第一项目个人总结
- 第一本书总结~~~
- bh第一学期总结
- 第一期学完总结
- 自己总结第一弹
- 第一个项目总结
- CSS3实现文字渐隐效果
- Record-2-1
- 关于Linux环境下的android真机调试
- Ubuntu Eclipse CDT编译动态链接库文件报错recompile with -fPIC错误
- 【C++】容器类
- 啊希吧!第一场队内赛总结
- Linux网络编程之socket文件传输示例
- PHP用户登录功能实现
- hdoj1860
- 实习日记--20150721
- Quartz集群配置(一)
- RMQ(区间最值查询)入门知识
- Python 学习笔记一之模块探究学习
- JAVA模拟浏览器调用rest api接口