1题 跑步训练
$10000/300=33...100$
$10000-32*300=400$
$600/60=10$
$400/10+32*2*60=3880s$
2题 阶乘约数
#include <iostream>
using namespace std;
int p[100];
int main()
{
for (int i = 2; i <= 100; ++i)
{
int n = i;
for (int j = 2; j*j <= n; ++j)
while(n % j == 0)
{
++p[j];
n /= j;
}
if(n > 1) ++p[n];
}
long long ans = 1;
for (int i = 2; i <= 100; ++i)
if(p[i]) ans *= (p[i] + 1);
cout << ans << endl;
return 0;
}
39001250856960000
3题 出栈次序
#include <iostream>
using namespace std;
int f(int n,int m)
{
if(n == 0)
return 1;
if(m == 0)
return f(n - 1,1);
return f(n - 1,m + 1) + f(n,m - 1);
}
int main()
{
cout<<f(16,0);
return 0;
}
35357670
4题 哥德巴赫分解
#include <iostream>
using namespace std;
bool is_prime(int num) {
for (int i = 2; i*i <=num; ++i)
if (num % i == 0) return false;
return true;
}
int main() {
int m = 0;
for (int i = 10000; i > 3; i -= 2) {
for (int j = 2; j <= i/2; ++j) {
if (is_prime(j) && is_prime(i - j)) {
m = max(m, j);
break;
}
}
}
cout << m << endl;
return 0;
}
173
5题 图书排列
#include <iostream>
using namespace std;
int a[]={1,2,3,4,5,6,7,8,9,10};
int main()
{
int ans=0;
do
{
if(abs(a[0]-a[1])==1) continue;
if(abs(a[1]-a[2])==1) continue;
if(abs(a[2]-a[3])==1) continue;
if(abs(a[3]-a[4])==1) continue;
if(abs(a[4]-a[5])==1) continue;
if(abs(a[5]-a[6])==1) continue;
if(abs(a[6]-a[7])==1) continue;
if(abs(a[7]-a[8])==1) continue;
if(abs(a[8]-a[9])==1) continue;
ans++;
}while(next_permutation(a,a+10));
cout<<ans<<endl;
return 0;
}
//479306
6题 猴子分香蕉
#include <iostream>
using namespace std;
int main()
{
int i=6;
while(true)
{
if(i%5==1)
{
int x1=i-(i-1)/5;
x1=x1-1;
if(x1%5==2)
{
int x2=x1-(x1-2)/5;
x2=x2-2;
if(x2%5==3)
{
int x3=x2-(x2-3)/5;
x3=x3-3;
if(x3%5==4)
{
int x4=x3-(x3-4)/5;
x4=x4-4;
if(x4%5==0 && x4!=0)
{
cout<<i<<endl;
break;
}
}
}
}
}
i++;
}
return 0;
}
3141
7题 稍小分数
int gcd(int a, int b) {
if(b==0) return a;
return gcd(b,a%b);
}
int main() {
int a = 7;
int b = 13;
int m,n;
int max_a = 0;
int max_b = 1;
for(n=100; n>1; --n) {
for(m=n-1; m>=1; --m) {
if(m*b<a*n && gcd(m,n)==1) {
if( max_b*m>(max_a*n) ) {
max_a = m;
max_b = n;
break;
}
}
}
}
printf("%d/%d\n", max_a, max_b);
return 0;
}
8题 excel地址
#include <iostream>
#include <cstring>
using namespace std;
int ans[100];
int main()
{
long n;
cin>>n;
int cnt=0;
while(n)
{
if(n%26==0)
{
ans[cnt++]=26;//特殊处理,能除尽的情况下,把26作为余数
n=n/26-1;//商减少1,作为被除数
}
else
{
ans[cnt++]=n%26;//正常情况,记录余数
n/=26;//商作为被除数
}
}
for(int i=cnt-1;i>=0;i--)
{
cout<<(char)('A'+(ans[i]-1));
}
return 0;
}
9题 日期问题
#include<cstdio>
#include<vector>
using namespace std;
int a[3];
const int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
struct Date{
int a,b,c;
}d[3];
bool com(Date x,Date y){
if(x.a!=y.a)return x.a<y.a;
if(x.b!=y.b)return x.b<y.b;
return x.c<y.c;
}
int main(){
scanf("%d/%d/%d",&a[0],&a[1],&a[2]);
d[0].a=a[0]+(a[0]<60?2000:1900),d[0].b=a[1],d[0].c=a[2];
d[1].a=a[2]+(a[2]<60?2000:1900),d[1].b=a[0],d[1].c=a[1];
d[2].a=a[2]+(a[2]<60?2000:1900),d[2].b=a[1],d[2].c=a[0];
for(int i=0;i<3;i++){
for(int j=i+1;j<3;j++){
if(!com(d[i],d[j])){
Date t=d[i];
d[i]=d[j];
d[j]=t;
}
}
}
for(int i=0;i<3;i++){
printf("%d-%02d-%02d\n",d[i].a,d[i].b,d[i].c);
}
return 0;
}
10题 整数划分
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 55;
int n;
int f[N][N]={0};
int main()
{
while(cin >> n)
{
f[0][0] = 1;
for(int i = 1; i <= n; i++)
{
for(int j = 0; j <= n; j++)
{
for(int k = 0; k * i <= j; k++)
{
f[i][j] += f[i - 1][j - k * i];
}
}
}
cout << f[n][n] << endl;
}
return 0;
}
11题 一步之遥
#include <iostream>
using namespace std;
const int maxn = 1000;
int main(){
for(int i = 0; i < maxn; ++i){
for(int j = 0; j < maxn; ++j){
if(97 * i - 127 * j == 1){
cout << i <<" "<< j <<endl;
return 0;
}
}
}
return 0;
}
12题 机器人塔
13题 七星填空
//全排列
do
{
}while(next_permutation(a,a+10))
#include<iostream>
#include<algorithm>
using namespace std;
int a[20]={1,2,3,4,5,7,8,9,10,12,13};
int main()
{
do
{
int x1=a[0]+a[1]+a[2]+a[3];
int x2=a[0]+a[4]+a[6]+a[9];
int x3=6+a[1]+a[4]+14;
int x4=6+a[2]+a[5]+11;
int x5=a[3]+a[5]+a[7]+a[10];
int x6=14+a[6]+a[8]+a[10];
int x7=a[9]+a[8]+a[7]+11;
if(x1==x2 && x1==x3 && x1==x4 && x1==x5 && x1==x6 && x1==x7)
{
for(int i=0;i<11;i++)
cout<<a[i]<<" ";
cout<<endl;
}
}while(next_permutation(a,a+10));
return 0;
}