神奇的快读,本人已懵
  • 板块灌水区
  • 楼主DX3906_ourstar
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/9/29 13:23
  • 上次更新2024/9/29 18:13:43
查看原帖
神奇的快读,本人已懵
1268524
DX3906_ourstar楼主2024/9/29 13:23

rt,写某道神仙毒瘤题的时候被卡了输入途径,于是我果断选择快读

本来的快读是这样的:

#define re register
inline __int128 read(){
	int x = 0,f = 1;
	re char c = getchar_unlocked();
	while(c < '0' || c > '9'){
		if(c == '-'){
			f = -1;
		}
		c = getchar_unlocked();
	}
	while(c >= '0' && c <= '9'){
		x = x * 10 + c - '0';
		c = getchar_unlocked();
	}
	return x * f;
}

可以发现,这个快读是考虑了负数的。但题目数据中不存在负数,我就去掉了考虑负数的代码,改成了这样:

#define re register
inline unsigned __int128 read(){
	int x = 0;
	re char c = getchar_unlocked();
	while(c >= '0' && c <= '9'){
		x = x * 10 + c - '0';
		c = getchar_unlocked();
	}
	return x;
}

但一交,发现WA完了

后来偶然发现,如果保留针对负数的代码,但不让其结果对答案产生贡献,居然也能过:

#define re register
inline unsigned __int128 read(){
	int x = 0,f = 1;
	re char c = getchar_unlocked();
	while(c < '0' || c > '9'){
		if(c == '-'){
			f = -1;
		}
		c = getchar_unlocked();
	}
	while(c >= '0' && c <= '9'){
		x = x * 10 + c - '0';
		c = getchar_unlocked();
	}
	return x;
}

本人已懵,求助

2024/9/29 13:23
加载中...