#includeintri(){char c =getchar();int x =0, f =1;for(;c <'0'|| c >'9'; c =getchar())if(c =='-') f =-1;for(;c >='0'&& c <='9'; c =getchar()) x =(x <<1)+(x <<3)-'0'+ c;return x * f;}intmain(){int b =ri(), k =ri(), n =0;for(int i =1;i <= k;++i)
n =(n * b +ri())&1;puts(n ?"odd":"even");return0;}
B. Tape
题意
给你一条长度为m的绳子,上面有n处断点,利用要最多k条胶带覆盖这些断点,最小化长度。
题解
取前k大的断点间隔即可。记得掐头去尾。
代码
#includeconstint N =1e5+10;intri(){char c =getchar();int x =0, f =1;for(;c <'0'|| c >'9'; c =getchar())if(c =='-') f =-1;for(;c >='0'&& c <='9'; c =getchar()) x =(x <<1)+(x <<3)-'0'+ c;return x * f;}int n, m, k, b[N];intmain(){
n =ri(); m =ri(); k =ri();for(int i =0;i < n;++i)
b[i]=ri();int All = b[n -1]- b[0]+1, Sum =0;for(int i = n -1; i;--i)
b[i]-= b[i -1]+1;
std::sort(b +1, b + n);for(int i =1; i < k && i < n;++i)
Sum += b[n - i];printf("%d
", All - Sum);return0;}
#includeintri(){char c =getchar();int x =0, f =1;for(;c <'0'|| c >'9'; c =getchar())if(c =='-') f =-1;for(;c >='0'&& c <='9'; c =getchar()) x =(x <<1)+(x <<3)-'0'+ c;return x * f;}int bin[30];constint biao[]={1,1,5,1,21,1,85,73,341,89,1365,1,5461,4681,21845,1,87381,1,349525,299593,1398101,178481,5592405,1082401};intmain(){
bin[0]=1;for(int i =1;i <=25;++i)
bin[i]= bin[i -1]<<1;int q =ri();for(;q--;){int a =ri(), mx;for(int i =24;~i;--i)if(a >= bin[i]){
mx = i +1;break;}if(bin[mx]-1== a)printf("%d
", biao[mx -2]);elseprintf("%d
", bin[mx]-1);}return0;}