又一道简单题&&Ladygod(两道思维水题)

Ladygod

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

有一天人诹Lee在随手帮女神做题,突然女神发现了自己演算纸上的一个式子,但是式子只有两个加数却没有结果,最近在学不同进制加减法的女神忘了这个两个数字是多少进制了(只记得是小于等于1010),但是她很好奇在可能的多少进制下这个式子得到的答案长度最长,为了从人赢Lee手中抢走女神,你需要快速计算出这个答案,例如78+87=78+87=? 在1010进制下是165165,在99进制下是176176,而小于等于88的进制显然是不合法的,所以这个式子答案可能的最长长度就是33.

Input

第一行读入一个整数 T(1T100000)T(1≤T≤100000) 表示数据组数

接下来有TT行

每行含两个数A,BA,B (不超过44位的非00整数)

Output

对于每个数据输出一个数字,表示可能的答案的最大长度

Sample input and output

Sample InputSample Output
2
78 87
1 1
3 
2

题解:这个题还错了好多次,因为进制不同,相加的进位也不同,我直接把两个数字当成10进制算了,肯定错了。。。

其实就是一个a+b问题,让找不同进制的最大长度。。。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
typedef long long LL;
const int MAXN=10;
int ans;

void work(int x,int y,int p){
    int a[MAXN],b[MAXN],c[MAXN];
    int t1=0,t2=0;
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    while(x)a[t1++]=x%10,x/=10;
    while(y)b[t2++]=y%10,y/=10;
    int t=max(t1,t2);
    for(int i=0;i<t;i++){
        c[i]=a[i]+b[i]+c[i];
        c[i+1]=c[i]/p;
        c[i]%=p;
        if(c[t])t++;
    }
    ans=max(ans,t);
}
int main(){
    int T;
    SI(T);
    int p;
    while(T--){
        int x,y,temp;
        scanf("%d%d",&x,&y);
        temp=x;
        p=1;
        while(temp){
            p=max(p,temp%10);
            temp/=10;
        }
        temp=y;
        while(temp){
            p=max(p,temp%10);
            temp/=10;
        }
    //    printf("%d
",p);
    ans=0;
    for(int i=p+1;i<=10;i++){
        work(x,y,i);
    }
        printf("%d
",ans);
    }
    return 0;
}
View Code
  • [1647] 又一道简单题

  • 时间限制: 5000 ms 内存限制: 65535 K
  • 问题描述
  • 输入一个四个数字组成的整数 n,你的任务是数一数有多少种方法,恰好修改一个数字,把它 变成一个完全平方数(不能把首位修改成 0)。比如 n=7844,有两种方法:3844=62^2和 7744=88^2。

  • 输入
  • 输入第一行为整数 T (1<=T<=1000),即测试数据的组数,以后每行包含一个整数 n (1000<=n<=9999)。
  • 输出
  • 对于每组数据,输出恰好修改一个数字,把 n 变成完全平方数的方案数。
  • 样例输入
  • 2
    7844
    9121
  • 样例输出
  • Case 1: 2
    Case 2: 0

 题解:给一个4位数字,问随便改变一位,是另一个数的平方;有多少种。。。我一直想着改变一个数字,没找到好的方法,果断就挂了,因为就4位数字,暴力不就好了,一直想着开根号。。。还真是怎么麻烦怎么来,然并卵;

代码:

extern "C++"{
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
const double Pi=acos(-1.0);
typedef long long LL;
typedef unsigned u;
typedef unsigned long long uLL;
void SI(int &x){scanf("%d",&x);}
void SI(LL &x){scanf("%lld",&x);}
void SI(u &x){scanf("%u",&x);}
void SI(uLL &x){scanf("%llu",&x);}
void SI(double &x){scanf("%lf",&x);}
void SI(char *x){scanf("%s",&x);}

void PI(int &x){printf("%d",x);}
void PI(LL &x){printf("%lld",x);}
void PI(u &x){printf("%u",x);}
void PI(uLL &x){printf("%llu",x);}
void PI(double &x){printf("%lf",x);}
void PI(char *x){printf("%s",x);}
#define mem(x,y) memset(x,y,sizeof(x))
#define NL puts("");
}
bool js(int x,int y){
    int num=0;
    while(x){
        if(x%10!=y%10)num++;
        x/=10;y/=10;
    }
    if(num==1)return true;
    return false;
}
int main(){
    int T,kase = 0,x;
    SI(T);
    while(T--){
        SI(x);
        int ans = 0;
        for(int i = 10;i < 100;i++){
            if(i*i >= 1000){
                if(js(i*i,x) )
                    ans++;
            }
        }
        printf("Case %d: %d
",++kase,ans);
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/handsomecui/p/5315320.html