此文章可以使用目录功能哟↑(点击上方[+])

 Kattis <Zamka>

Accept: 0    Submit: 0
Time Limit: 1 second    Memory Limit : 1024 MB

 Problem Description

The impossible has happened. Bear G. has fallen into his own trap. Lured by a delicious box of Domaćica, without even thinking, he rushed and fell into his trap. In order to get out of the trap, he must solve the following task with your help. You are given three integers L, D and X.

  • determine the minimal integer N such that L≤N≤D and the sum of its digits is X
  • determine the maximal integer M such that L≤M≤D and the sum of its digits is X

Bear will be able to escape from the trap if he correctly determines numbers N and M. The numbers N and M will always exist.

 Input

The first line of input contains the integer L (1≤L≤10000), the number from the task. The second line of input contains the integer D(1≤D≤10000, L≤D), the number from the task. The third line of input contains the integer X (1≤X≤36), the number from the task.

 Output

The first line of output must contain the integer N from the task. The second line of output must contain the integer M from the task.

 Sample Input

1
100
4
100
500
12
1
10000
1

 Sample Output

4
40
129
480
1
10000

 Problem Idea

解题思路:

【题意】

问题一:在区间[L,D]内找到一个最小整数N,使得其各位数字之和为X

问题二:在区间[L,D]内找到一个最大整数M,使得其各位数字之和为X

【类型】
暴力

【分析】

想要根据各位数字之和是X在区间[L,D]内直接确定出N和M还是有难度的

但考虑到区间[L,D]的最大区间长度为10000

所以可以采用暴力枚举法

从L开始向D枚举(从小到大枚举),直到出现第一个[各位数字之和是X的]数,则该数即为N

再从D开始向L枚举(从大到小枚举),直到出现第一个[各位数字之和是X的]数,则该数即为M

【时间复杂度&&优化】
O((D-L+1)×digit(i))

题目链接→Kattis <Zamka>

 Source Code

/*Sherlock and Watson and Adler*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define eps 1e-9
#define LL long long
#define PI acos(-1.0)
#define bitnum(a) __builtin_popcount(a)
using namespace std;
const int N = 6;
const int M = 100005;
const int inf = 1000000007;
const int mod = 10007;
int judge(int x)
{int sum=0;while(x){sum+=x%10;x/=10;}return sum;
}
int main()
{int L,D,X,i;scanf("%d",&L);scanf("%d",&D);scanf("%d",&X);for(i=L;i<=D;i++)if(judge(i)==X){printf("%d\n",i);break;}for(i=D;i>=L;i--)if(judge(i)==X){printf("%d\n",i);break;}return 0;
}

菜鸟成长记

Kattis Zamka相关推荐

  1. Kattis - icpccamp ICPC Camp(二分+贪心)

    题目链接:点击查看 题目大意:给出两种种类的数字分别 m1m_1m1​ 和 m2m_2m2​ 个,现在要求匹配 nnn 个不同种类的数字,每个数字只能使用一次,且两数之和不能超过 sss,输出任意两对 ...

  2. Kattis Problem-Unique Snowflakes

    Kattis Problem-Unique Snowflakes 原题链接 题目类型:双指针 题意 给定一个整数序列,找出最长的不重复子串的长度. 分析 使用双指针,枚举每个指针 I,然后每次判断指针 ...

  3. 关于优先队列在图中的应用G - Millionaire Madness Kattis - millionairemadness

    G - Millionaire Madness Kattis - millionairemadness 文章大意:就是给你一个n*m的图(int)代表货物的高度),可以上下左右移动一次一格,但是去高度 ...

  4. Kattis - bela

    Bela Young Mirko is a smart, but mischievous boy who often wanders around parks looking for new idea ...

  5. Kattis之旅——Prime Reduction

    A prime number p≥2 is an integer which is evenly divisible by only two integers: 1 and p. A composit ...

  6. 水题Kattis Temperature Confusion小学数学

    题目 Sample Input 1 Sample Output 132/10/1Sample Input 2 Sample Output 233/15/9Sample Input 3 Sample O ...

  7. kattis ones简单题取模运算+枚举

    题目链接原链接 题目 给定不被2和5整除的整数n,有些n的倍数是十进制中的1的序列(比如111,1111111).其中最小的一个1的序列是几位数字? 比如数字3的37倍是111.所以是三位 Given ...

  8. 【Kattis - triangle 】Sierpiński Circumference(数学,求位数,取对数或Java)

    题干: Polish mathematician Wacław Sierpiński (1882-1969) described the 2D geometric figure known as th ...

  9. Zoning Houses Kattis 多组记录线段树/ST表

    1.题意:给你n个平面上的点,再给你m个询问,每个询问包括[ l, r ]内的点,让你求出包含这些点在内的最小正方形的边长,你可以忽略这些点内的一个点. 2.分析:如果不忽略点,我们只需要取这些点中的 ...

  10. D - Dragon Balls Kattis - dragonballs

    题目链接 题意:交互题,就是提问系统不超过1000次然后找到n颗龙珠,但龙珠是1颗1颗找到的并不是1次全部找到,这样就很简单了,每次循环输出1个(0,0),然后找到与远点相聚为d的所有的点,然后在分别 ...

最新文章

  1. I hope so 2016-Oct-10
  2. 架构与思维:系统容量设计
  3. Java多态性Polymorphic
  4. html javascript 音频、视频、 mp3 、mp4 的播放、暂停、重新播放、获取音频时长、视频自动全屏播放
  5. layerui的弹出层只显示两行英文字符不换行的解决方法
  6. 假如古代有了云计算,延禧攻略里的各位嫔妃要如何宫斗
  7. 小猴子蓝裤黄袄 即时通讯
  8. 图片热点的使用,html area 的用法
  9. bp神经网络测试_BP 神经网络驱动的手写体数字识别软件 EasyOCR
  10. javaWeb:相关监听方法汇总
  11. php jwt token刷新方案,解决使用jwt刷新token带来的问题
  12. ac8265网卡linux驱动,英特尔8265无线网卡驱动
  13. git 强制回滚到某个commit版本
  14. 实现 | 朴素贝叶斯模型算法研究与实例分析
  15. CCIE-MPLS路由传递
  16. MySQL5.7官方下载链接导航
  17. 【Lambda】LCAC第十四次会议重要内容摘取
  18. 史上最详细的RACI(责任分配矩阵)使用方法及实例详解
  19. B/S聊天室(websocket)
  20. iptv是什么意思?什么是iptv?

热门文章

  1. java实现九九乘法表
  2. rose怎么画业务流程图_子流程图怎么画(流程图中的子流程)
  3. 【软件工程】系统流程图——期末快速复习用
  4. 我不建议大家随便跳槽
  5. 计算机类课题研究方法,课题研究方法有哪些
  6. 【神通数据库】图形化界面安装、命令行安装、静默安装、命令行建数据库、日常维护(超详细)
  7. 植物大战僵尸C语言修改器
  8. 关于文件你必须了解的一些基本概念
  9. 田忌赛马博弈矩阵分析
  10. 解决K650C ubuntu下不能重启关机问题