CodeForces346 C. Number Transformation II】的更多相关文章

C. Number Transformation II time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a sequence of positive integers x1, x2, ..., xn and two non-negative integers a and b. Your task is…
Number Transformation II 题解: 对于操作2来说, a - a % x[i] 就会到左边离a最近的x[i]的倍数. 也就是说 [ k * x[i] + 1,  (k+1)* x[i] -1 ]这段区间的的数都会走到 k * x[i]上. 所以对于每个位置都先计算出他到右边最远的覆盖位置. 然后在反着求出每个位置能往左走走到的最远的位置. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freo…
1 题目描述: 被给一系列的正整数x1,x2,x3...xn和两个非负整数a和b,通过下面两步操作将a转化为b: 1.对当前的a减1. 2.对当前a减去a % xi (i=1,2...n). 计算a转化到b最小需要的最短步数. 2 输入 第一行包含简单的整数n(1 ≤  n ≤ 10^5),第二行包含n个用空格分开的整数x1,x2,x3...xn(2 ≤  xi ≤ 10^9),第三行包含两个整数a和b(0  ≤ b ≤  a ≤ 10^9, a - b ≤ 10^6). 3 输出 输出一个整数…
题目链接:点击打开链接 = = 990+ms卡过 #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<vector> #include<set> using namespace std; #define N 100010 #define L(x) (x<<1) #define R(x) (x<<…
http://122.207.68.93/OnlineJudge/problem.php?id=1299 第二个样例解释.. 3 6 3->4->6..两步.. 由此可以BFS也可以DP..但关键是要离线把100000内每个数的约数情况预先处理出来..否则会超时... Program: #include<iostream> #include<stdio.h> #include<cmath> #include<cstring> #include&l…
题意及思路:https://www.cnblogs.com/liuzhanshan/p/6560499.html 这个做法的复杂度看似是O(n ^ 2),实际上均摊是O(n)的.我们考虑两种极端数据:一种是全是2,那么去重后实际上只有一个数.这样是O(n)的.另一种是所有的数都不一样,那么为了让最大的那个最小,数分别为2, 3 ...1e5, 1e5 + 1, 但是a和b之差最多只有1e6,这种情况甚至比刚才那种耗时更少.故复杂度均摊是O(n)的. 代码: #include <bits/stdc…
2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transformation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 85 Accepted Submission(s): 31 Problem Descr…
Single Number: 1. Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 代码: class Solution { publi…
3858: Number Transformation Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 82  Solved: 41[Submit][Status] Description Teacher Mai has an integer x. He does the following operations k times. In the i-th operation, x becomes the least integer no less th…
http://acm.hdu.edu.cn/showproblem.php?pid=4952 Number Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 171    Accepted Submission(s): 69 Problem Description Teacher Mai has an inte…
Number Transformation 我们能发现这个东西是以2 - k的lcm作为一个循环节, 然后bfs就好啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int,…
891 ModricWang's Number Theory II 思路 使得序列的最大公约数不为1,就是大于等于2,就是找到一个大于等于2的数,它能够整除序列中的所有数. 考虑使得一个数d整除数组中所有数的代价: 如果一个数不能被b整除,那么可以花费x的代价删掉它,或者通过多次加1使得它可以被d整除,代价应该为 \((d - a[i]\%d) * y\) , \((a[i] \% d == 0s时特判,应该为0)\) 令 \(l = x / y\) 如果\(d - a[i] \% d <= l…
Number Transformation In this problem, you are given an integer number s. You can transform any integer number A to another integer number B by adding x to A. This x is an integer number which is a prime factor of A (please note that 1 and A are not…
[1]LeetCode 136 Single Number 题意:奇数个数,其中除了一个数只出现一次外,其他数都是成对出现,比如1,2,2,3,3...,求出该单个数. 解法:容易想到异或的性质,两个相同的数异或为0,那么把这串数从头到尾异或起来,最后的数就是要求的那个数. 代码如下: class Solution { public: int singleNumber(vector<int>& nums) { ; ;i<nums.size();i++) sum ^= nums[i…
Single Number I : Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Solution: 解法不少,贴一种: class…
Given an array of integers, every element appears twice except for one. Find that single one. 本题利用XOR的特性, X^0 = X, X^X = 0, 并且XOR满足交换律. class Solution(object): def singleNumber(self, nums): """ :type nums: List[int] :rtype: int ""…
I title: Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 思路:异或 class Solution { public: int…
Description In this problem, you are given a pair of integers A and B. You can transform any integer number A to B by adding x to A.This x is an integer number which is a prime below A.Now,your task is to find the minimum number of transformation req…
Problem statement Elementary knowledge: There is a popular question when I seeked my job at Beijing: swap the value of two numbers without allocate a new memory. Normally, there are two solutions: 1 int main(){ 2 int a = 3; 3 int b = 5; 4 5 a += b; 6…
Single Number Given an array of integers, every element appears twice except for one. Find that single one. def singleNumber(self, A): l = len(A) if l < 2: return A[0] A.sort() for i in range(0,l-1,2): if A[i] != A[i+1]: return A[i] return A[l-1] 思路:…
Single Number I Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 直接异或解决. class Solution { pu…
Given an array of integers, every element appears twice except for one. Find that single one. 思路: 最经典的方法,利用两个相同的数异或结果为0的性质,则将整个数组进行异或,相同的数俩俩异或,最后得到的就是那个single number,复杂度是O(n) 代码: class Solution { public: int singleNumber(vector<int>& nums) { int…
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description You are given a sequence of positive integers x1, x2, ..., xn and two non-negative integers a and b. Your task is to transform a into b. To do that, you can per…
In this problem, you are given an integer number s. You can transform any integer number A to another integer number B by adding x to A. This x is an integer number which is a prime factor of A (please note that 1 and A are not being considered as a…
In this problem, you are given an integer number s. You can transform any integer number A to another integer number B by adding x to A. This x is an integer number which is a prime factor of A (please note that 1 and A are not being considered as a…
题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值,求出这个固定的值和K相乘就可以了, 为什么会趋于固定的值呢,因为最后虽然i在不断增长,但是x也是在增长的,每次的倍数会回退一个发现 有余数,然后再加上一个,所以趋于稳定. 官方题解: #include <iostream> #include <cstdio> #include <…
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3858 题解:设第i个数为i*a;第i+1个数为(i+1)*b.则(i+1)*b>i*a;b>a-(a/(i+1));那么如果a<i+1;b的值就会不变 此时k*b就为所求:而由于a在不断的变小,a<i+1;在数值比较大的情况下就能实现这么乱搞都行?!代码: #include<cstdio> #include<cstdlib> #include<cm…
寻找1~k内i的倍数.则这个数能够看成i*x,则下一个数为(i+1)*y,(i+1)*y>=i*x,那么能够推出.y=x-x/(i+1); 那么当x<i+1时,y==x.之后的循环也不会改变,就能够跳出. #include<stdio.h> __int64 x,y,k; int main() { __int64 i; int flag; __int64 sum; int cas=0; while(scanf("%I64d%I64d",&x,&k)…
题意及思路:https://blog.csdn.net/bossup/article/details/37076965 代码: #include <bits/stdc++.h> #define LL long long #define INF 1e18 using namespace std; int lcm(int x, int y) { return x * y / __gcd(x, y); } const int maxn = 500010; LL a, b, k; LL dp[maxn…
哎.这个题想了好久,状态不对啊...一个大家都出的题..当时想到肯定是可以有什么规律来暴力,不用算到10的10次方 对于某个k,x.从1到k循环,每次求一个新的x,这个x要大于等于原x,并且要是i的倍数... 一直觉得有规律可循,后来知道就是倍数,我们设倍数为 b, 则b2*(i+1)>=b1*(i);可以知道b2>=b1-b1/(i+1),则,b2在b1小于等于i+1的时候便不会再变换,题目最大的倍数为10的10次方,根据第一个式子,最多经过10的五次方,倍数就会缩为10的五次方,此时i也&…