CSUFT 个人赛(2) C题(POJ - 1316) D题(HDU - 2076) G题(HihoCoder - 1740) H题(HDU - 5640)

其实 今天个人赛打得不好emmm

出了很多小差错...

在下面的内容里会好好分析


        C题  原题地址 (POJ - 1316)

In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called self-numbers. For any positive integer n, define d(n) to be n plus the sum of the digits of n. (The d stands for digitadition, a term coined by Kaprekar.) For example, d(75) = 75 + 7 + 5 = 87. Given any positive integer n as a starting point, you can construct the infinite increasing sequence of integers n, d(n), d(d(n)), d(d(d(n))), .... For example, if you start with 33, the next number is 33 + 3 + 3 = 39, the next is 39 + 3 + 9 = 51, the next is 51 + 5 + 1 = 57, and so you generate the sequence 

33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, ... 
The number n is called a generator of d(n). In the sequence above, 33 is a generator of 39, 39 is a generator of 51, 51 is a generator of 57, and so on. Some numbers have more than one generator: for example, 101 has two generators, 91 and 100. A number with no generators is a self-number. There are thirteen self-numbers less than 100: 1, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86, and 97. 

Input
No input for this problem.
Output
Write a program to output all positive self-numbers less than 10000 in increasing order, one per line.
Sample Input
Sample Output 
1
3
5
7
9
20
31
42
53
64
 |
 |       <-- a lot more numbers
 |
9903
9914
9925
9927
9938
9949
9960
9971
9982
9993


暴力题  

某个数的各个位上的数字之和加上其本身的数 不能叫做子数  求10000以内所有的子数 (垃圾翻译)

第一遍写的时候 分类讨论 1~9  10~99  100~999  1000~9999

写了好多个循环来做不同位数的处理

交题之后 果断超时了...

又想了想 不是可以直接 考虑1~9999 将个位、十位、百位、千位上的数字取出来 再进行运算

上代码:

#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
    int n,m[10010];
    int a,b,c,d;
    for (int i=1; i<10000; i++)
        m[i]=i;
    for (int i=1; i<10000; i++)
    {
        a=i%10;
        b=i/10%10;
        c=i/100%10;
        d=i/1000;
        m[a+b+c+d+i]=0;
    }
    for (int i=1; i<10000; i++)
        if (m[i]>0)
            printf("%d\n",m[i]);
    return 0;
}


接下来 

    D题  原题地址 (HDU - 2076)

时间过的好快,一个学期就这么的过去了,xhd在傻傻的看着表,出于对数据的渴望,突然他想知道这个表的时针和分针的夹角是多少。现在xhd知道的只有时间,请你帮他算出这个夹角。 

注:夹角的范围[0,180],时针和分针的转动是连续而不是离散的。 
Input输入数据的第一行是一个数据T,表示有T组数据。 
每组数据有三个整数h(0 <= h < 24),m(0 <= m < 60),s(0 <= s < 60)分别表示时、分、秒。
Output对于每组输入数据,输出夹角的大小的整数部分。 
Sample Input
2
8 3 17
5 13 30
Sample Output
138
75

数学题  按照公式来就行

x 记录时针从0开始转过的角度

y 记录分针从0开始转过的角度

两者相减  如果该值大于180 则需要用360减去该值

同时要 注意 输入的h 大于12时 需要减去12 (相当于时针多走了一圈)

最后 输出的时候要取整数部分

这道题 在比赛的时候WA了5次 真的心态炸裂

比赛结束后 又交了好几遍去找 WA的点


其实真的是很小的一个注意点

double 型的数据在乘除的时候要带上小数点!!!

尤其是除法的时候!!!

上代码  (fabs()是对double 或是 float 类型的数取正值)

#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,a,b,c;
    double m,k,x,y;
    scanf("%d",&n);
    for (int i=0; i<n; i++)
    {
        scanf("%d%d%d",&a,&b,&c);
        x=(a%12)*30+b*0.5+c*0.5/60;
        y=b*6+c*0.1;
        m=fabs(x-y);
        if (m>180)
            m=360-m;
        printf("%d\n",(int)m);
    }
    return 0;
}


G题 原题地址  (HihoCoder - 1740)

已知替换函数replace(c1, c2)的作用是把一个字符串中所有的c1字符替换成c2字符。  

请你判断能否使用replace函数将字符串S变成D。  

你可以调用replace函数任意多次。

Input

输入包含多组数据。  

第一行包含一个整数T,代表数据组数。  

每组数据包含两行,分别是字符串S和D。

1 ≤ T ≤ 10

S和T都只包含小写字母,且1 ≤ |S| = |D| ≤ 1000

Output

对于每组数据输出YES或者NO,表示能否使用replace函数将字符串S变成D。

Sample Input
2  
aaabb  
ccccc  
aaabbbbb  
cccccddd
Sample Output
YES  
NO

在代码里放解释吧...

写这题的时候脑子有点乱

结果 数组只开了50 (我也不知道为啥)

比赛结束之后 重新开了数组就过了 也是水题

#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
char a[2000],b[2000];
int x[2000],y[2000];
bool flag;
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=0; i<n; i++)
    {
        flag=true;
        memset(x,0,sizeof x);//x数组 清零
        memset(a,' ',sizeof a);//清空a数组
        memset(b,' ',sizeof b);//清空b数组
        scanf("%s",a);
        scanf("%s",b);
        int len1=strlen(a);
        int len2=strlen(b);
        if (len1!=len2) //判断两个字串是否长度相等
            flag=false;
        for (int j=0; j<len1-1; j++)
            for (int k=j+1; k<len1; k++)
                //如果 a数组中 某一个字符 和 后一个字符 相同
                //那么 他们对应的b数组中相同位置的字符也应该相同
            {
                if (a[j]==a[k]&&b[j]!=b[k])
                    flag=false;
            }
        if (flag)
            printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


     H题  原题地址 (HDU - 5640)

It is the king's birthday before the military parade . The ministers prepared a rectangle cake of size  n×m(1n,m10000)n×m(1≤n,m≤10000) . The king plans to cut the cake himself. But he has a strange habit of cutting cakes. Each time, he will cut the rectangle cake into two pieces, one of which should be a square cake.. Since he loves squares , he will cut the biggest square cake. He will continue to do that until all the pieces are square. Now can you tell him how many pieces he can get when he finishes.
InputThe first line contains a number  T(T1000)T(T≤1000), the number of the testcases. 

For each testcase, the first line and the only line contains two positive numbers  n,m(1n,m10000)n,m(1≤n,m≤10000).OutputFor each testcase, print a single number as the answer.Sample Input
2
2 3
2 5
Sample Output
3
4

hint:
For the first testcase you can divide the into one cake of $2\times2$ , 2 cakes of $1\times 1$


思路:因为蛋糕都是正方形的 所以每次都是切 长或宽 的较小值 才能取到最大的蛋糕

先判断 长宽的大小 然后做循环处理

上代码:

#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,a,b,sum;
    scanf("%d",&n);
    for (int i=0; i<n; i++)
    {
        sum=0;
        scanf("%d%d",&a,&b);
        if (a<b)
        {
            a=a+b;
            b=a-b;
            a=a-b;
        }
        while (b>0)
        {
            a=a-b;
            sum++;
            if (a<b)
            {
                a=a+b;
                b=a-b;
                a=a-b;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

继续加油啊~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值