加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

hdu 4068 I-number【大数】

发布时间:2020-12-14 04:04:49 所属栏目:大数据 来源:网络整理
导读:题目: http://acm.hdu.edu.cn/showproblem.php?pid=4608 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#problem/G 2013暑期多校联合训练——80+高校,300+队伍,10000元奖金,敬请期待~ I-number Time Limit: 10000/5000 MS (Java/Others)?

题目:

http://acm.hdu.edu.cn/showproblem.php?pid=4608

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#problem/G

2013暑期多校联合训练——80+高校,300+队伍,10000元奖金,敬请期待~

I-number

Time Limit: 10000/5000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1006????Accepted Submission(s): 398


Problem Description
The I-number of x is defined to be an integer y,which satisfied the the conditions below:
1.?y>x;
2.?the sum of each digit of y(under base 10) is the multiple of 10;
3.?among all integers that satisfy the two conditions above,y shouble be the minimum.
Given x,you're required to calculate the I-number of x.
?

Input
An integer T(T≤100) will exist in the first line of input,indicating the number of test cases.
The following T lines describe all the queries,each with a positive integer x. The length of x will not exceed 10 5.
?

Output
Output the I-number of x for each query.
?

Sample Input
       
       
1 202
?

Sample Output
       
       
208
?

Source
2013 Multi-University Training Contest 1
?

Recommend
liuyiding
?


题意:


第一个数 T 代表测试数据组数

每组给你一个大数 N (N的长度 <= 100000)

求最小的 > N 且满足每一位相加的总和能够整除 10 的数


算法:


大数相加,只是+1比较简单,随便模拟一下就好了

思路:


不断的 + 1 直到满足情况
官方题解中也说的是最多+20个 1 就可以求出

昨天白天比赛的时候是 浩神 AC 的,KB 神也和我说了下怎么做,白天看了下 浩神的代码,自己写,还是要 WA
昨晚比赛时按照浩神的思路纠结出了 AC的代码
刚刚问了下 KB 神,原来是掉了个初始化,改了也 AC 了


code:

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

const int maxn = 200000;
int a[maxn];
char str[maxn];
int len;

void add()
{
    int c = 1;
    for(int i = 0;; i++)
    {
        int tmp = a[i]+c;
        a[i] = tmp%10;
        c = tmp/10;
        if(c == 0) break; //加到没有进位
    }
    if(a[len] != 0) len++; //加到头有进位
}

bool judge()
{
    int sum = 0;
    for(int i = 0; i < len; i++)
        sum += a[i];
    return sum%10;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s",str);
        len = strlen(str);

        memset(a,sizeof(a)); //不能少否则会WA,前面的组a[len]可能会有价
        int j = len;
        for(int i = 0; i < len; i++) a[i] = str[--j]-'0';
        add();
        while(judge()) add();

        for(int i = len-1; i >= 0; i--) printf("%d",a[i]);
        printf("n");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

const int maxn = 200000;
int a[maxn];
char str[maxn];
int len;

void add()
{
    int c = 1;
    for(int i = 0; i < len; i++)
    {
        int tmp = a[i]+c;
        a[i] = tmp%10;
        c = tmp/10;
        if(c == 0) return;
    }
    a[len] = c; len++;
    return;
}

int judge()
{
    int sum = 0;
    for(int i = 0; i < len; i++)
    {
        sum += a[i];
    }
    return sum%10;
}
int main()
{
    int T;
    scanf("%d",str);
        len = strlen(str);

        int j = len;
        for(int i = 0; i < len; i++) a[i] = str[--j]-'0';
        add();
        while(judge()) add();

        for(int i = len-1; i >= 0; i--) printf("%d",a[i]);
        printf("n");
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读