HDU 6075 Questionnaire(水~)

xiaoxiao2021-02-28  102

Description 给出n个整数,要求给出两个整数m,k使得模m为k的数的个数不少于模m不为k的数的个数 Input 第一行一整数T表示用例组数,每组用例首先输入一整数n表示数的个数,之后输入n个整数a[i] (1<=T<=15,3<=n<=1e5,1<=a[i]<=1e9) Output 输出两个整数m和k(m > 1,0<=k < m) Sample Input 1 6 23 3 18 8 13 9 Sample Output 5 3 Solution 统计奇数偶数的个数即可,奇数多就2 1,偶数多就2 0 Code

#include<cstdio> using namespace std; namespace fastIO { #define BUF_SIZE 100000 //fread -> read bool IOerror=0; inline char nc() { static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE; if(p1==pend) { p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin); if(pend==p1) { IOerror=1; return -1; } } return *p1++; } inline bool blank(char ch) { return ch==' '||ch=='\n'||ch=='\r'||ch=='\t'; } inline void read(int &x) { char ch; while(blank(ch=nc())); if(IOerror)return; for(x=ch-'0';(ch=nc())>='0'&&ch<='9';x=x*10+ch-'0'); } #undef BUF_SIZE }; using namespace fastIO; int main() { int T,n,a; read(T); while(T--) { read(n); int num=0; for(int i=1;i<=n;i++) { read(a); if(a&1)num++; } if(num>=(n+1)/2)printf("2 1\n"); else printf("2 0\n"); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-78431.html

最新回复(0)