题目链接:点击打开链接 = = 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<<…
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…
题意及思路: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…
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 我们能发现这个东西是以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,…
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 输出 输出一个整数…
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://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…
题目:戳这里 题意:有1,2,3...n这n个数,求一次这些数的gcd,删去一个数,直到剩下一个数为止.输出这n个gcd的最大字典序. 解题思路:一开始的gcd肯定是1,要让字典序最大,我们可以想到下一个应该是2.这样就要把所有的奇数全给删去,这样就要考虑一个特殊情况,就是把所有奇数删去之后,刚好n==1的时候.因为n==1的话,gcd就是剩下的那个数本身了.因此要特判n==3的情况.其他的时候循环删除奇数的操作.(要不是b题看不懂题意,这次也不会那么惨T T 具体看代码. 1 #include…
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…
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…
题目链接:Codeforces 486C Palindrome Transformation 题目大意:给定一个字符串,长度N.指针位置P,问说最少花多少步将字符串变成回文串. 解题思路:事实上仅仅要是对称位置不同样的.那么指针肯定要先移动到这里,改动字符仅仅须要考虑两种方向哪种更优即 可. 然后将全部须要到达的位置跳出来.贪心处理. #include <cstdio> #include <cstring> #include <cstdlib> #include <…
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…
点击打开链接 C. Palindrome Transformation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is m…
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…
题意 给出一个1-n的集合   gcd 集合里面的所有数  得到的 一个 数   然后自己选择删去一个数   要使得到的数 构成的数列 的字典序最大 思路: gcd所有数 那gcd得到的数肯定要小于数组中最小的数  所以 刚开始都是1   所以优先删去1  那就要使gcd所有数经可能快得到 2 如何快速到2 呢 那就是把奇数全部删掉  那剩下得数最小就为2 了  此时为 2 4 6 8 10....  此刻就从2开始删   当n==3时 有 x ,2x,3x  此时 只有 删 x 2 x   3…
B. z-sort 题目连接: http://www.codeforces.com/contest/652/problem/B Description A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold: ai ≥ ai - 1 for all even i, ai ≤ ai - 1 for all…
[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…
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits:  5000 MS   Memory Limits:  200000 KB 64-bit interger IO format:  %lld   Java class name:  Main Description A Hill Number is a number whose digits possibly rise and then possibl…
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…
http://codeforces.com/contest/235/problem/E 远距离orz......rng_58 证明可以见这里(可能要FQ才能看到) 还是copy一下证明吧: 记 $$f(a,b,c)=\sum\limits_{i=1}^{a}\sum\limits_{j=1}^{b}\sum\limits_{k=1}^{c}d(ijk)$$ 和 $$g(a,b,c)=\sum\limits_{gcd(i,j)=gcd(j,k)=gcd(i,k)=1}\left \lfloor \…
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…
题目传送门 传送门I 传送门II 题目大意 给定一个$n\times m$的网格,每个格子上要么填$1$,要么填$-1$,有$k$个位置上的数是已经填好的,其他位置都是空的.问有多少种填法使得任意一行或一列上的数的乘积为$-1$. $1 \leqslant n, m \leqslant 10^{3}$,$1 \leqslant k < \max (n, m)$. $k$的范围醒目.那么意味着至少存在一行或者一列为空. 假设空的是一行.那么剩下的行只需要满足那一行的乘积为$-1$,而空的这一行对应…
109. Magic of David Copperfield II time limit per test: 0.25 sec. memory limit per test: 4096 KB The well-known magician David Copperfield loves lo show the following trick: a square with N rows and N columns of different pictures appears on a TV scr…