election
#include <cstdio>
#include <cstdlib>
int cmp(const void *p, const void *q){
return *(int *)p - *(int *)q;
}
int main(){
freopen("election.in", "r", stdin);
freopen("election.out", "w", stdout);
int t, k, a[1010];
scanf("%d", &t);
while (t--){
scanf("%d", &k);
for (int i=0; i<k; i++)
scanf("%d", &a[i]);
qsort(a, k, sizeof(int), cmp);
int ans=0;
for (int i=0; i<=k/2; i++)
ans+=a[i]/2+1;
printf("%d\n", ans);
}
return 0;
}
digit
#include <stdio.h>
#include <string.h>
const int M=1000001;
char s[M];
int main(){
freopen("digit.in","r",stdin);
freopen("digit.out","w",stdout);
int t;
scanf("%d", &t);
while (t--){
scanf("%s", s);
int ans1=0, len=strlen(s), pos;
for (int i=0; i<len; i++){
if (s[i]=='x') {
s[i]='9';
pos=i;
}//求最后一个x的位置:pos
ans1=(ans1*10+s[i]-'0')%77;
}
//先求xxxx全填9999时s除以77的余数:ans1
if (ans1==0){ /*
for (int i=0; i<=pos-4; i++)
printf("%c", s[i]);
printf("9999");
for (int i=pos+1; i<len; i++)
printf("%c", s[i]);
printf("\n");*/
puts(s);
continue;
}//如果全填9999恰好能整除,直接输出
int ans2=1, ten=10, tpos=len-pos-1;
while (tpos>0){
if (tpos%2) ans2=ans2 * ten %77;
tpos/=2; ten=ten*ten%77;
}//再求10的tpos次方对77的余数: ans2,算法:快速幂
int k=1, ans3=ans2;
while (ans3!=ans1){
k++;
ans3=ans2*k%77;
}//再求k*ans2 % 77的余数等于 ans1 的第一个k值
for (int i=0; i<=pos-4; i++)
printf("%c", s[i]);
printf("%d", 9999-k);
for (int i=pos+1; i<len; i++)
printf("%c", s[i]);
printf("\n");
}
return 0;
}
/*
1xxxx987
19999987 : ans1 =5
1000 : ans2 =1
5000 5
19994987
*/
squares
#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
using namespace std;
int a[10][2];
int main(){
freopen("squares.in","r",stdin);
freopen("squares.out","w",stdout);
ll n, s, fm, to;
cin>>n;
/*fm=1ll; to=(long long)(pow((24.0)*n, 1.0/3)/2-1);
s=to*(to+1)*(to*2+1)/6; //纯数学方法直接计算出to
*/
fm=1ll; s=fm*fm; to=fm;
int ns=(int)(sqrt(1.0*n)), ans=0;
while (to<=ns){
if (s<n){
to++; s+=to*to;
}//队尾入列
else if (s>n){
s-=fm*fm; fm++;
}//队首出列
else {
a[ans][0]=(int)(fm); a[ans][1]=(int)(to);
ans++; to++; s+=to*to;
}
}
printf("%d\n", ans);
for (int i=0; i<ans; i++){
printf("%d %d\n", a[i][0],a[i][1]);
}
return 0;
}
温馨提示:内容为网友见解,仅供参考