TYVJ 1463 智商问题
Time Limit: 1.5 Sec Memory Limit: 512 MB
题目连接
http://www.tyvj.cn/p/1463
背景
各种数据结构帝~
各种小姊妹帝~
各种一遍AC帝~ 来吧!
Description
某个同学又有很多小姊妹了
他喜欢聪明的小姊妹 所以经常用神奇的函数来估算小姊妹的智商
他得出了自己所有小姊妹的智商
小姊妹的智商都是非负整数
但是这个同学看到别的同学的小姊妹
也喜欢用神奇的函数估算一下
然后看看这个小姊妹在自己的小姊妹群体中排在第几位...
(这么邪恶的兴趣...)
Input
第一行一个整数N 代表小姊妹的个数
第二行N个整数 代表这位同学N个小姊妹的智商
接下来若干行 每行一个整数
代表这位同学看中的别人的小姊妹的智商
0<=智商<=2^31-1
0<=N<=1000000
Output
输出若干行
每行一个整数 回答新的小姊妹
在原来小姊妹中智商的排名
Sample Input
Sample Output
HINT
数据量很大
C语言用scanf输入输出!
另外 这个同学的小姊妹群体在这个题中是不会变的~
他会在看完所有别的同学的小姊妹之后...
大家听说过 苏格拉底和麦田的故事的吧...
题解:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1200001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/*
*/
//**************************************************************************************
inline ll read()
{
int x=0,f=1;char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
return x*f;
}
int a[maxn];
int last[maxn];
int n,k;
int work(int x)
{
for(int i=1;i<=k+1;i++)
if(x<=last[i]&&x>last[i-1])
{
int b=(i-1)*k;
for(int j=1;j<=k;j++)
{
if(a[b+j]>=x)
return b+j;
}
}
}
int main()
{
int n=read();
for(int i=1;i<=n;i++)
a[i]=read();
sort(a+1,a+1+n);
k=(int)sqrt(n);
for(int i=1;i<=k;i++)
last[i]=a[i*k];
last[k+1]=a[n];
int x;
while(scanf("%d",&x)!=EOF)
{
if(x<a[1])
printf("1\n");
else if(x>a[n])
printf("%d\n",n+1);
else
printf("%d\n",work(x));
}
return 0;
}