- cin cout 的速度比scanf printf 慢,有的题目因为超时没法通过,要考虑使用scanf printf
比如 [NCT058A]签到题 https://ac.nowcoder.com/acm/contest/11198/A 以下不能通过
#include<iostream>
#include<algorithm>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,q;
scanf("%d%d", &n, &q);
long long a[n];
long long x,y;
int i,j,k;
int sum;
for(i=0;i<n;i++)
{
cin>>a[i];
a[i]*=a[i];
}
sort(a,a+n);
for(i=0;i<q;i++)
{
cin>>x>>y;
sum = upper_bound(a,a+n, x*x+y*y)-a;
cout<<sum<<endl;
}
}
而这个可以通过
#include<iostream>
#include<algorithm>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,q;
scanf("%d%d", &n, &q);
long long a[n];
long long x,y;
int i,j,k;
int sum;
for(i=0;i<n;i++)
{
scanf("%lld",&a[i]);
a[i]*=a[i];
}
sort(a,a+n);
for(i=0;i<q;i++)
{
scanf("%lld%lld", &x, &y);
sum = upper_bound(a,a+n, x*x+y*y)-a;
printf("%d\n",sum);
}
}
|