best coder #17 1002 Select
来源:互联网 发布:mysql text使用 编辑:程序博客网 时间:2024/04/30 19:01
一开始想到这么去做了,但是算了一下会爆时间,就没写,后来发现原来有这么个函数,,lower_bound()。真是长知识了,作用就是查找单调递增的序列中大于等于某一值的元素的下标,网上有大牛介绍的很详细。在此膜拜一下,有了这个时间久妥妥的了,,
#include<iostream>#include<algorithm>#include<stdio.h>using namespace std;long long a[110],b[100010],ans1,ans2;int main(){ int n,k,t,top,m; scanf("%d",&t); while(scanf("%d %d",&n,&k)!=EOF) { top=0; ans1=0; for(int i=1;i<=n;i++) { scanf("%d",&m); for(int j=0;j<m;j++) { scanf("%I64d",&a[j]); b[top++]=a[j]; } sort(a,a+m); for(int j=0;j<m-1;j++) { ans1+=m-(lower_bound(a+j+1,a+m,k-a[j]+1)-a); // printf("%I64d\n",ans1); } } sort(b,b+top); ans2=0; for(int j=0;j<top-1;j++) { ans2+=top-(lower_bound(b+j+1,b+top,k-b[j]+1)-b); } printf("%I64d\n",ans2-ans1); } return 0;}
对于又一次爆零我只想说,,,感觉不会再爱了,晚安!!
0 0
- best coder #17 1002 Select
- best coder 第六场
- best coder 资格赛D
- 【Best Coder】Go to movies
- 【Best Coder】#36 C tree
- Best Coder Matrix(数学)
- Best Coder Lotus and Characters
- Best Coder MG loves gold
- hdu 4883 (Best Coder) TIANKENG’s restaurant
- Best Coder Round 12【so easy】
- Best coder 2014-3-14题解
- 【Best Coder】#34 B Building Blocks
- hdu-4883- (Best Coder) TIANKENG’s restaurant
- Best coder 52div21001Victor and Machine
- Best Coder 1003 string(dp)
- 裂变位法加密 best coder
- Best Coder #92 1001 Skip The Class
- Who do you think is the best coder and why?
- HDU's ACM 1009 FatMouse' Trade
- 单片机精解
- UVA - 11078 Open Credit System
- MS-Gvim的安装和配置
- 易语言操作短信猫
- best coder #17 1002 Select
- 手机指令大全
- PopupMenu
- 《机器学习实战》读书笔记—k近邻算法c语言实现(win下)
- 用一个类实现网络通讯功能:<nstream>
- Tutorials for 2014 SWJTU Freshman Invitation Programming Contest - Online Round
- MAC下安装与配置MySQL
- 细胞词库的解码C源程序
- Python集合(set)类型的基本操作