a_bottle @ 2019-12-22 17:53:57
因为有负数所以这么写的,本地测过了但是洛谷没过
求问原因
int read()
{
int x=0,q=0;
char ch=getchar();
if(ch=='-')
{
q=1;
}
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9')
{
x=(x<<3)+(x<<1)+ch-'0';
ch=getchar();
}
if(q)return -x;
return x;
}
by A_Plus_Gu @ 2019-12-22 18:16:23
@kevinhou 不对吧
by Resonaa @ 2019-12-22 18:27:48
@OIer_Zheng
我用事实说话。
代码:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
using namespace std;
int a,g[200000001],n;
int read()
{
int x=0,q=0;
char ch=getchar();
while(ch<'0'||ch>'9')
{
ch=getchar();
if(ch=='-')
{
q=1;
}
}
while(ch>='0'&&ch<='9')
{
x=(x<<3)+(x<<1)+ch-'0';
ch=getchar();
}
if(q) return -x;
return x;
}
int main()
{
srand(time(NULL));
a=rand()*rand()%200000000+1;
freopen("slow.in","w",stdout);
printf("%d\n",a);
for(int i=0;i<a;i++)
g[i]=(rand()%2==0?-1:1)*(rand()*rand()%100000000),printf("%d ",g[i]);
fclose(stdout);
freopen("fast.in","w",stdout);
printf("%d\n",a);
for(int i=0;i<a;i++)
printf("%d ",g[i]);
fclose(stdout);
freopen("con","w",stdout);
freopen("fast.in","r",stdin);
int t=clock();
n=read();
//printf("%d",n);
for(int i=0;i<n;i++) g[i]=read();
printf("快读用时%d\n",(clock()-t));
fclose(stdin);
freopen("slow.in","r",stdin);
t=clock();
scanf("%d",&n);
//printf("%d",n);
for(int i=0;i<n;i++) scanf("%d",&g[i]);
printf("scanf用时%d\n",(clock()-t));
return 0;
}
by 1saunoya @ 2019-12-22 18:39:42
@kevinhou fnmdp
const static int _ = 1 << 20 ;
char fin[_] , * p1 = fin , * p2 = fin ;
inline char gc() { return (p1 == p2) && (p2 = (p1 = fin) + fread(fin , 1 , _ , stdin) , p1 == p2) ? EOF : * p1 ++ ; }
inline int read() {
bool sign = 1 ; char c = 0 ; while(c < 48) ((c = gc()) == 45) && (sign = 0) ;
int x = (c & 15) ; while((c = gc()) > 47) x = (x << 1) + (x << 3) + (c & 15) ;
return sign ? x : -x ;
}
by Provicy @ 2019-12-22 18:42:32
@kevinhou 你自己去做做卡常题保证以你的常数写个快读都过不去更别说scanf了/cy
by hly1204 @ 2019-12-22 18:50:43
这个快读不够快。。先要把函数名改成fast_read之类的才行吧