K - Integer Game Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UVA 11489 题意:在n中取数字,使剩下的数是3的倍数,不能取则失败. 思路:如果能使当前数为3的倍数,数字和必是3的倍数.要保持这种状态,先对每一位对3取余,统计cnt[0],cnt[1],cnt[2]; 的个数,整个串能否被3整除取决于ans=(cnt[1]+cnt[2]*2)%3;…
/** 题目:K - Large Division 链接:https://vjudge.net/contest/154246#problem/K 题意:判断a是否是b的倍数. a (-10^200 ≤ a ≤ 10^200) and b (|b| > 0, b fits into a 32 bit signed integer). 思路:取余: */ #include<iostream> #include<cstring> #include<cstdio> #in…
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can replace n with either n + 1 or n - 1. What is the minimum number of replacements needed for n to become 1? Example 1: Input: 8 Outp…
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can replace n with either n + 1 or n - 1. What is the minimum number of replacements needed for n to become 1? Example 1: Input: 8 Outp…
B. Maximum Value Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/problem/B Description You are given a sequence a consisting of n integers. Find the maximum possible value of (integer remainder of ai divided by aj), whe…
Problem: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 终于什么都没参考就一次Accept了.可能是这题比较简单,同时自己也进步了一点点,leetcode就是这样给我们增加信心的吧. 我是这样想的,利用除10和模10两个操作,将每个数字分离在vec中,然后相应的乘以10的倍数输出就行.如果这个数在-10与10之间直接返回就好. 代码如下: class S…
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2. Example…
POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may as…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6441 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Descriptionpeople in USSS love math very much, and there is a famous math problem .give you two integers n,a,…
Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple of k, that is, sums up to n*k where n is also an integer. Example 1: Input:…
非负数组中找到和为K的倍数的连续子数组 详见:https://leetcode.com/problems/continuous-subarray-sum/description/ Java实现: 方法一: class Solution { public boolean checkSubarraySum(int[] nums, int k) { for(int i=0;i<nums.length;++i){ int sum=nums[i]; for(int j=i+1;j<nums.length…
倍数问题 题目描述 [题目描述] 众所周知,小葱同学擅长计算,尤其擅长计算一个数是否是另外一个数的倍数.但小葱只擅长两个数的情况,当有很多个数之后就会比较苦恼.现在小葱给了你 n 个数,希望你从这 n 个数中找到三个数,使得这三个数的和是 K 的倍数,且这个和最大.数据保证一定有解. [输入格式] 从标准输入读入数据. 第一行包括 2 个正整数 n, K. 第二行 n 个正整数,代表给定的 n 个数. [输出格式] 输出到标准输出. 输出一行一个整数代表所求的和. [样例输入] 4 3 1 2…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/smallest-integer-divisible-by-k/ 题目描述 Given a positive integer K, you need find the smallest positive integer N such that N is divisible b…
[LeetCode]397. Integer Replacement 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/integer-replacement/description/ 题目描述: Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you…
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Have you thought about this? Here are some good questions to ask before coding. Bonus points for you if you have already thought through this! If the integer'…
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get. For example, given n = 2, return 1 (2 = 1 + 1); given n = 10, return 36 (10 = 3 +…
Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1. For example, 123 -> "One Hundred Twenty Three" 12345 -> "Twelve Thousand Three Hundred Forty Five" 1234567 -&g…
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 罗马数转化成数字问题,我们需要对于罗马数字很熟悉才能完成转换.以下截自百度百科: 罗马数字是最早的数字表示方式,比阿拉伯数字早2000多年,起源于罗马. 如今我们最常见的罗马数字就是钟表的表盘符号:Ⅰ,Ⅱ,Ⅲ,Ⅳ(IIII),Ⅴ,Ⅵ,Ⅶ,Ⅷ,Ⅸ,Ⅹ,Ⅺ,Ⅻ…… 对应阿拉伯数字(就是现…
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 之前那篇文章写的是罗马数字转化成整数(http://www.cnblogs.com/grandyang/p/4120857.html), 这次变成了整数转化成罗马数字,基本算法还是一样.由于题目中限定了输入数字的范围(1 - 3999), 使得题目变得简单了不少. 基本字符 I V…
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for this problem to be spe…