寻找乐子
2026-01-24 19:37:09
发布于:上海
0阅读
0回复
0点赞
极致压缩,2ms, 1.44MB
#include<stdio.h>
// 使用更小的缓冲区(64KB)
static inline char nc() {
static char buf[65536], *p = buf, *q = buf;
return p == q && (q = (p = buf) + fread(buf, 1, 65536, stdin), p == q)
? EOF : *p++;
}
static inline int read() {
int x = 0;
char ch = nc();
while (ch < '0' || ch > '9') ch = nc();
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch - '0');
ch = nc();
}
return x;
}
int main() {
int t = read();
// 更小的输出缓冲区,动态刷新
char out_buf[32768];
int out_pos = 0;
while (t--) {
int x = read(); // x是3/5/7这样的小数字,用int足够
// 直接比较,避免函数调用
if (x == 3 || x == 5 || x == 7) {
// 检查缓冲区是否足够
if (out_pos + 4 > 32768) {
fwrite(out_buf, 1, out_pos, stdout);
out_pos = 0;
}
out_buf[out_pos++] = 'Y';
out_buf[out_pos++] = 'E';
out_buf[out_pos++] = 'S';
out_buf[out_pos++] = '\n';
} else {
if (out_pos + 3 > 32768) {
fwrite(out_buf, 1, out_pos, stdout);
out_pos = 0;
}
out_buf[out_pos++] = 'N';
out_buf[out_pos++] = 'O';
out_buf[out_pos++] = '\n';
}
}
// 输出剩余内容
if (out_pos > 0) {
fwrite(out_buf, 1, out_pos, stdout);
}
return 0;
}
这里空空如也




有帮助,赞一个