3 条题解
-
0
分奇偶
奇数项平均值存在且为整数,与偶数项相等
使用s1,s2记录奇数项与偶数项的和,使用n1,n2记录奇数项和偶数项的项数。
核心代码
有注释
tt=read_(); //s应为longlong,否则溢出(被坑了) s1=0;n1=0;s2=0;n2=0; while(tt--){ s2+=read_();n2++; //合并偶数/奇数操作,使用if排除奇数项与偶数项不相等的情况 if(tt--){s1+=read_();n1++;}else{break;} } //首先保证整除 if(s2%n2){write_str("NO\n");continue;} if(s1%n1){write_str("NO\n");continue;} //其次判断相等 if(s1/n1==s2/n2)write_str("YES\n");else write_str("NO\n");
AC代码
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <sys/stat.h> #include <sys/mman.h> #include <unistd.h> #define N1 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1 #define N2 N1,N1,N1,N1,N1,N1,N1,N1,N1,N1 #define N3 N2,N2,N2,N2,N2,N2,N2,N2,N2,N2 #define N4 N3,N3,N3,N3,N3,N3,N3,N3,N3,N3 #define D(a) a,1##a,2##a,3##a,4##a,5##a,6##a,7##a,8##a,9##a #define S246 N2,N2,N1,N1,N1,N1,-1,-1,-1,-1,-1,-1 const int _mp[0x10000] = { N4,N3,N3,N2,N2,N2,N1,N1,N1,-1,-1,-1,-1,-1,-1, D(0),S246,D(1),S246,D(2),S246,D(3),S246,D(4),S246, D(5),S246,D(6),S246,D(7),S246,D(8),S246,D(9), N4,N4,N4,N4,N4,N2,N2,N2,N2,N2,N2,N2,N2,N1,N1,N1,N1,N1,N1,N1,N1, -1,-1,-1,-1,-1,-1 }; #undef N1 #undef N2 #undef N3 #undef N4 #undef D #undef S246 char *buf_ptr; char *buf_end; char out_buf[1 << 20]; char *pp = out_buf; void io_init(){ struct stat sb; fstat(0,&sb); buf_ptr=(char*)mmap(NULL,sb.st_size,PROT_READ,MAP_PRIVATE,0,0); buf_end=buf_ptr+sb.st_size; } int read_(){ int x=0,f=0; while(buf_ptr<buf_end && *buf_ptr<=' ') buf_ptr++; if(buf_ptr>=buf_end) return 0; if(*buf_ptr=='-'){ f=1; buf_ptr++; } while(buf_ptr+1<buf_end){ int v=_mp[*(uint16_t*)buf_ptr]; if(v==-1) break; x = x*100 + v; buf_ptr += 2; } if(buf_ptr<buf_end && *buf_ptr>='0' && *buf_ptr<='9'){ x = x*10 + (*buf_ptr - '0'); buf_ptr++; } return f ? -x : x; } void push(char c){ if(pp - out_buf == (1<<20)){ fwrite(out_buf,1,1<<20,stdout); pp = out_buf; } *pp++ = c; } void write_(int x){ if(x<0){ push('-'); x = -x; } static int sta[40]; int top=0; do{ sta[top++] = x%10; x/=10; } while(x); while(top) push(sta[--top] + '0'); } void write_str(const char* s){ while(*s) push(*s++); } void io_flush(){ fwrite(out_buf,1,pp - out_buf,stdout); } int gc(){return(unsigned char)*buf_ptr++;} static inline void mvp(int n){buf_ptr+=n;} int main() { io_init(); int t,tt,n1,n2; long long s1,s2; t=read_(); while(t--){ tt=read_(); s1=0;n1=0;s2=0;n2=0; while(tt--){ s2+=read_();n2++; if(tt--){s1+=read_();n1++;}else{break;} } if(s2%n2){write_str("NO\n");continue;} if(s1%n1){write_str("NO\n");continue;} if(s1/n1==s2/n2)write_str("YES\n");else write_str("NO\n"); } io_flush(); return 0; }
信息
- ID
- 1097
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 156
- 已通过
- 25
- 上传者