10.23基本功训练解题报告

题目:problem

因为依旧是水题 所以还是直接发代码

1.Hanoi 问题-2

// <1.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
int n,m,con,ans;
int MM(int n, int m){
if(n%m!=0)return n/m+1;
else return n/m;
}
int HH(int n){
if(n==1)return 1;
if(n==2)return 3;
else return 2*HH(n-1)+1;
}
int main(){
freopen(“1.in”,”r”,stdin);
freopen(“1.out”,”w”,stdout);
scanf(“%d%d”,&n,&m);
con=MM(n,m);
ans=HH(con);
printf(“%d\n”,ans);
return 0;
}

2.DNA 序列

// <2.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
const int maxn=1010;
int getint(){
int res=0,fh=1;char ch=getchar();
while((ch>’9’||ch<‘0′)&&ch!=’-‘)ch=getchar();
if(ch==’-‘)fh=-1,ch=getchar();
while(ch>=’0’&&ch<=’9’)res=res*10+ch-‘0’,ch=getchar();
return res;
}
int n,i,j,k[maxn],ans,ok;
char s[13][maxn];
int main(){
freopen(“2.in”,”r”,stdin);
freopen(“2.out”,”w”,stdout);
n=getint();
for(i=1;i<=n;i++)scanf(“%s”,s[i]);
int len=strlen(s[1]);
for(i=0;i<len;i++){
k[1]=0;k[2]=0;k[3]=0;k[4]=0;
for(j=1;j<=n;j++)switch (s[j][i]){
case ‘A’:k[1]++;break;
case ‘C’:k[2]++;break;
case ‘G’:k[3]++;break;
case ‘T’:k[4]++;break;
}
ans=0;
for(j=1;j<=4;j++)if(k[j]>ans){
ok=j;
ans=k[j];
}
switch(ok){
case 1:cout<<“A”;break;
case 2:cout<<“C”;break;
case 3:cout<<“G”;break;
case 4:cout<<“T”;break;
}
}
return 0;
}

3.数的读法

// <3.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
char* num[10]={“ling”,”yi”,”er”,”san”,”si”,”wu”,”liu”,”qi”,”ba”,”jiu”};
char* wei[5]={“shi”,”bai”,”qian”,”wan”,”yi”};
int main(){
freopen(“3.in”,”r”,stdin);
freopen(“3.out”,”w”,stdout);
char* str[20];
int i,j,k,n,l[2]={0};
i=j=0;
scanf(“%d”,&n);
while(n>0){
k=n%10;
n/=10;
if(k>0){
if(i>0){
if(i>=4&&!l[i/4-1]){
l[i/4-1]=1;
str[j++]=wei[i/4+2];
}
if(i%4!=0)str[j++]=wei[i%4-1];
}
str[j++]=num[k];
}else if(j>0 && str[j-1]!=num[0]){
str[j++]=num[0];
}
i++;
}
if(!(str[j-1]==”yi”&&j>1&&str[j-2]==”shi”))printf(“%s “,str[j-1]);
for(i=j-2;i>=0;i–)printf(“%s “,str[i]);
return 0;
}

4.The Next Cow

// <4.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
lol n;
int main(){
freopen(“4.in”,”r”,stdin);
freopen(“4.out”,”w”,stdout);
cin>>n;
cout<<n+1<<endl;
return 0;
}

5.奶牛的罢工

// <5.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
lol n;
bool check(lol a){
lol b=sqrt(a);
lol i;
for(i=2;i<=b;i++)if(a%i==0)return 0;
return 1;
}
int main(){
freopen(“5.in”,”r”,stdin);
freopen(“5.out”,”w”,stdout);
cin>>n;n++;
while(!check(n))n++;
cout<<n;
return 0;
}

6.FJ的字符串

// <6.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
string s[30];
void An(int n){
int i;
if(n==1){
s[1]=”A”;
return;
}
char c=’A’+n-1;
s[n]=s[n-1]+c+s[n-1];
return;
}
int main(){
freopen(“6.in”,”r”,stdin);
freopen(“6.out”,”w”,stdout);
int n;
scanf(“%d”,&n);
for(int i=1;i<=n;i++)An(i);
cout<<s[n]<<endl;
return 0;
}

7.芯片测试

// <7.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
int n,a[25],f[25][25],suc=0;
void check(){
int i,j;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++){
if(a[i]==1&&f[i][j]!=a[j])return;
if(a[j]==1&&f[j][i]!=a[i])return;
}
suc=1;
for(i=1;i<=n;i++)if(a[i])printf(“%d “,i);
return;
}

void dfs(int d){
if (d==n+1){
check();
return;
}
int i;
if (d>2)
for (i=1;i<d-1;i++){
if(a[i]==1&&f[i][d-1]!=a[d-1])return;
if(a[d-1]==1&&f[d-1][i]!=a[i])return;
}
a[d]=1;
dfs(d+1);
if(suc)return;
a[d]=0;
dfs(d+1);
return;
}

int main()
{
freopen(“7.in”,”r”,stdin);
freopen(“7.out”,”w”,stdout);
int i,j;
scanf(“%d”,&n);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)scanf(“%d”,&f[i][j]);
dfs(1);
return 0;
}

8.求解二元整数不定方程

// <8.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
int getint(){
int res=0;
char ch=getchar();
while(ch<‘0’||ch>’9′)ch = getchar();
while(ch>=’0’&&ch<=’9’)res=res*10+ch-‘0’,ch=getchar();
return res;
}

int main(){
freopen(“8.in”,”r”,stdin);
freopen(“8.out”,”w”,stdout);
int a=getint(),b=getint(),m=getint();
for(int x=1;x<=m/a;x++)
for(int y=x;a*x+b*y<=m;y++)cout<<x<<“,”<<y<<endl;
return 0;
}

9.整除打印

// <9.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
int getint(){
int res=0;
char ch=getchar();
while(ch<‘0’||ch>’9′)ch = getchar();
while(ch>=’0’&&ch<=’9’)res=res*10+ch-‘0’,ch=getchar();
return res;
}

int main(){
freopen(“9.in”,”r”,stdin);
freopen(“9.out”,”w”,stdout);
int m=getint(),n=getint(),r=getint(),j=0;
for(int i=1;i<=m;i++)
if(i%n==r){
if(j)cout<<“,”;
cout<<i;
j++;
if(j==10){cout<<endl;j=0;}
}
return 0;
}

10.整数打印

// <10.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
int getint(){
int res=0;
char ch=getchar();
while(ch<‘0’||ch>’9′)ch = getchar();
while(ch>=’0’&&ch<=’9’)res=res*10+ch-‘0’,ch=getchar();
return res;
}

int main(){
freopen(“10.in”,”r”,stdin);
freopen(“10.out”,”w”,stdout);
int a=getint(),b=getint();
int now=a;
for(int i=1;i<=(b-a+5)/5;i++){
if(i&1){
for(int o=1;o<=5;o++)
if(now<=b)cout<<now++<<” “;
}
else{
for(int o=5;o>=1;o–){
if(now+2*(o-3)<=b)cout<<now+2*(o-3)<<” “;
else cout<<” “;
now++;
}
}
if(now>b)return 0;
cout<<endl;
}
}

11.调和数列问题

// <11.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
int main(){
freopen(“11.in”,”r”,stdin);
freopen(“11.out”,”w”,stdout);
double x;
while(1){
cin>>x;
if(x<0.001)return 0;
double now=0.0;
int n;
for(n=2;now<x;n++)now+=1.0/n;
cout<<n-2<<” card(s)”<<endl;
}
}

12.求因子个数

// <12.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
int getint(){
int res=0;
char ch=getchar();
while(ch<‘0’||ch>’9′)ch = getchar();
while(ch>=’0’&&ch<=’9’)res=res*10+ch-‘0’,ch=getchar();
return res;
}
int main(){
freopen(“12.in”,”r”,stdin);
freopen(“12.out”,”w”,stdout);
int n=getint(),ans=0;
for(int i=1;i<=n;i++)if(n%i==0)ans++;
cout<<ans;
return 0;
}

13.分解质因数

// <13.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
const int maxn=10010;
int getint(){
int res=0,fh=1;char ch=getchar();
while((ch>’9’||ch<‘0′)&&ch!=’-‘)ch=getchar();
if(ch==’-‘)fh=-1,ch=getchar();
while(ch>=’0’&&ch<=’9’)res=res*10+ch-‘0’,ch=getchar();
return res;
}
bool prime[maxn];
int n,k,xyk,a[maxn];
int main(){
freopen(“13.in”,”r”,stdin);
freopen(“13.out”,”w”,stdout);
memset(prime,false,sizeof(prime));
n=getint();
cout<<n<<“=”;k=0;
for(int i=2;i<=n;i++)
if (!prime[i]){
for(int j=i+i;j<=n;j+=i)prime[j]=1;
if(n%i==0)a[++k]=i;
}
for(int i=1;i<k;i++){
xyk=0;cout<<a[i];
while(n%a[i]==0)xyk++,n/=a[i];
if(xyk==1)cout<<“*”;else cout<<“^”<<xyk<<“*”;
}
xyk=0;cout<<a[k];
while(n%a[k]==0)xyk++,n/=a[k];
if(xyk!=1)cout<<“^”<<xyk;
return 0;
}

14.排名计算

// <14.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;

int main(){
freopen(“14.in”,”r”,stdin);
freopen(“14.out”,”w”,stdout);
cout<<“5 2 1 3 4”;
return 0;
}

15.寻找数组中最大值

// <15.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
int getint(){
int res=0;
char ch=getchar();
while(ch<‘0’||ch>’9′)ch = getchar();
while(ch>=’0’&&ch<=’9’)res=res*10+ch-‘0’,ch=getchar();
return res;
}
long long maxn=-1000000000,maxm;
int main(){
freopen(“15.in”,”r”,stdin);
freopen(“15.out”,”w”,stdout);
int n=getint(),a;
for(int i=0;i<n;i++){
scanf(“%d”,&a);
if(a>maxn){
maxn=a;
maxm=i;
}
}
cout<<maxn<<” “<<maxm;
return 0;
}

16.数字环打印

// <4.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
const int maxn=101;
int getint(){
int res=0,fh=1;char ch=getchar();
while((ch>’9’||ch<‘0′)&&ch!=’-‘)ch=getchar();
if(ch==’-‘)fh=-1,ch=getchar();
while(ch>=’0’&&ch<=’9’)res=res*10+ch-‘0’,ch=getchar();
return res;
}
int n,s,a[maxn][maxn];
int i,j;
int main(){
freopen(“16.in”,”r”,stdin);
freopen(“16.out”,”w”,stdout);
n=getint();s=getint();
memset(a,-1,sizeof(a));
for(i=1;i<=s;i++)a[i][1]=n,n++;
for(i=2;i<=s;i++)a[s][i]=n,n++;
for(i=s-1;i>=1;i–)a[i][s]=n,n++;
for(i=s-1;i>=2;i–)a[1][i]=n,n++;
for(i=1;i<=s;i++){
for(j=1;j<s;j++){
if(a[i][j]==-1)cout<<” “;
else cout<<a[i][j]<<” “;
}
cout<<a[i][j]<<endl;
}
return 0;
}

17.递归倒置字符数组

// <17.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
int getint(){
int res=0;
char ch=getchar();
while(ch<‘0’||ch>’9′)ch = getchar();
while(ch>=’0’&&ch<=’9’)res=res*10+ch-‘0’,ch=getchar();
return res;
}
string c;
void huan(int x,int y){
swap(c[x],c[y]);
cout<<c<<endl;
if(y-x>2)huan(x+1,y-1);
}
int main(){
freopen(“17.in”,”r”,stdin);
freopen(“17.out”,”w”,stdout);
int n=getint();
cin>>c;
if(n!=1)huan(0,n-1);
cout<<endl<<c;
return 0;
}

18.集合合并

// <18.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
int n,m,f[3050],ans;
int find(int x){
if(f[x]==x)return x;
int y=find(f[x]);
f[x]=y;
return y;
}
int main(){
freopen(“18.in”,”r”,stdin);
freopen(“18.out”,”w”,stdout);
scanf(“%d%d”,&n,&m);
ans=n;
int i,x,y,a,b;
for (i=1;i<=n;i++) f[i]=i;
for (i=1;i<=m;i++){
scanf(“%d%d”,&x,&y);
a=find(x);
b=find(y);
if(a!=b){
f[a]=b;
ans–;
}
}
cout<<ans<<endl;
return 0;
}

19.Fibonacci数列整除问题

// <19.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
const int maxn=10;
int getint(){
int res=0,fh=1;char ch=getchar();
while((ch>’9’||ch<‘0′)&&ch!=’-‘)ch=getchar();
if(ch==’-‘)fh=-1,ch=getchar();
while(ch>=’0’&&ch<=’9’)res=res*10+ch-‘0’,ch=getchar();
return res;
}
lol k[10002][4];
lol m[4];
int main(){
freopen(“19.in”,”r”,stdin);
freopen(“19.out”,”w”,stdout);
lol s,t;
cin>>s>>t>>m[0]>>m[1]>>m[2]>>m[3];
for(int i=0;i<4;i++)k[1][i]=1,k[2][i]=1;
for(int i=3;i<=t;i++)
for(int o=0;o<4;o++)k[i][o]=(k[i-1][o]+k[i-2][o])%m[o];
for(int i=s;i<=t;i++)
if(k[i][0]&&k[i][1]&&k[i][2]&&k[i][3])cout<<i<<” “;
return 0;
}

20.幻方

// <20.cpp> – 10/23/15 14:22:01
// This file is created by XuYike’s black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don’t know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
int getint(){
int res=0;
char ch=getchar();
while(ch<‘0’||ch>’9′)ch = getchar();
while(ch>=’0’&&ch<=’9’)res=res*10+ch-‘0’,ch=getchar();
return res;
}
int a[5][5],k;
bool q[17];
void src(int x,int y){
if(x==5){
k–;
if(!k){
for(int i=1;i<=4;i++){
for(int o=1;o<=4;o++)cout<<a[i][o]<<” “;
cout<<endl;
}
exit(0);
}
return;
}
for(int i=1;i<=16;i++)
if(!q[i]){
a[x][y]=i;
if(y==4){
int pl=0;
for(int i=1;i<=4;i++)pl+=a[x][i];
if(pl!=34)continue;
}else{
int pl=0;
for(int i=1;i<=y;i++)pl+=a[x][i];
if(pl>=34)return;
}
if(x==4){
int pl=0;
for(int i=1;i<=4;i++)pl+=a[i][y];
if(pl!=34)continue;
if(y==1){
int pl=0;
for(int i=1;i<=4;i++)pl+=a[5-i][i];
if(pl!=34)continue;
}
if(y==4){
int pl=0;
for(int i=1;i<=4;i++)pl+=a[i][i];
if(pl!=34)continue;
}
}else{
int pl=0;
for(int i=1;i<=x;i++)pl+=a[i][y];
if(pl>=34)continue;
}
q[i]=1;
y==4?src(x+1,1):src(x,y+1);
q[i]=0;
}
}
int main(){
freopen(“20.in”,”r”,stdin);
freopen(“20.out”,”w”,stdout);
k=getint();
src(1,1);
return 0;
}

说点什么

您将是第一位评论人!

提醒
wpDiscuz