题意:给你一个正整数\(x\),找两个正整数\(a\),\(b\),使得\(lcm(a,b)=x\),并且\(max(a,b)\)最小. 题解:我们知道,\(lcm(a,b)=a*b/gcd(a,b)\),所以如果\(a\)和\(b\)不互质,那么\(a*b\)必然可以约去一个\(gcd(a,b)\),也就表示\(max(a,b)\)的值可以变得更小,所以我们要找的\(a\)和\(b\)必然要互质,即得到\(gcd(a,b)=1\),从而推出\(a*b=x\),所以我们可以直接枚举到\(\sqr…
题意: LCM(a, b) = X,求 max(a, b) 的最小值. 思路: a, b 只可能存在于 X 的因子中,枚举即可. #include <bits/stdc++.h> using namespace std; typedef long long ll; ll lcm(ll a,ll b){ return a*b/__gcd(a,b); } void solve(){ ll n;cin>>n; ll ans=1; for(ll i=1;i*i<=n;i++) if(…
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such th…
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n 和你两场分赛的排名 x, y,问你最终名次最小和最大可能是多少. 思路: 以8人为例: x + y = 2,最小第一名,最大第一名:               1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1               x + y = 3,最小第一名,最大第二名.…
contest链接:https://codeforces.com/contest/1285 A. Mezo Playing Zoma 签到 #include<iostream> #include<vector> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<map>…
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have decided to watch the best moments of some movie. There are two buttons on your player: Watch the current minute…
题目链接:http://codeforces.com/contest/613/problem/D 题意概述: 给出一棵树,每次询问一些点,计算最少删除几个点可以让询问的点两两不连通,无解输出-1.保证询问的点总数不大于300000. 分析: 先考虑遍历的做法,统计每个点代表的子树中联通询问点的数量. 这个点不是询问点:如果有至少两个不同的子树中有询问点那么当前点一定被删除,因为这个时候不删除之后这两个点就是联通的:同时除了在更深的地方遇见第一种情况之外没有必要删除那些点:没有点不用管,只有一个点…
A略 直接求和最大的子序列即可(注意不能全部选中整个子序列) or #include<bits/stdc++.h> using namespace std; void solve(){ int n; cin>>n; vector<int> a(n); vector<long long> sum(n+1,0); for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=1;i<=…
构造两颗深度为30的字典树(根节点分别是0和1),结点只有0和1,从根节点向下DFS,贪心取答案. #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; vector<int>a; int dfs(vector<int>b,int x){ ||b.size()==)//30位都枚举完毕或当前向量中没有数字就中止 ; vector<int>c,d; ;i<b.s…
题意: 一个长为n的序列,是否存在与原序列不同的连续子序列,其元素之和大于等于原序列. 思路: 从前.后分别累加,若出现非正和,除此累加序列外的子序列元素之和一定大于等于原序列. #include <bits/stdc++.h> using namespace std; typedef long long ll; bool solve(){ int n;cin>>n; int a[n];for(int &i:a) cin>>i; ll sum=0; for(in…
题意: 给出一个移动序列,可以无效化一些指令,问可以移动到多少不同位置. 思路: 第一印象是统计左右指令数目,后来发现左右指令数目和即字符串长度. #include <bits/stdc++.h> using namespace std; int main() { int n;cin>>n; cout<<n+1<<endl; return 0; }…
题意:有一个长度为\(n\)的序列,找出最大的长度不为\(n\)的子段和,问最大子段和是否小于所有元素和. 题解:最大子段和我们可以直接用dp来找,每次状态转移为:\(dp[i]=max(dp[i-1]+a[i],a[i])\),而我们不能求长度为\(n\)的子段和,所以可以跑两次,从\([1,n-1]\)和\([2,n]\)维护一个最大值即可. 代码: int t; int n; ll a[N]; ll dp[N]; ll sum; int main() { //ios::sync_with_…
题目链接: http://codeforces.com/contest/712/problem/E 题目大意: 一条直线上有n格,在第i格有pi的可能性向右走一格,1-pi的可能性向左走一格,有2中操作:单点修改pi以及询问从L格出发最终从R格离开区间[L,R]的概率. 这题在cf上A的人比较少,本来不打算去做的,然后看了下是概率的题目,比较感兴趣,就去做了下,然后发现并不会做,就搜了题解. 题解: 参考http://www.cnblogs.com/qscqesze/p/5868047.html…
C. Gerald's Hexagon Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/problem/A Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he me…
题目链接 这个题取模的时候挺坑的!!! 题意:div(x , b) / mod(x , b) = k( 1 <= k <= a).求x的和 分析: 我们知道mod(x % b)的取值范围为 1  - (b-1).那么我们可以从这一点入口来进行解题.. mod (x, b) = 1 时, x  =  b + 1, 2b + 1, 3b + 1..... a * b + 1. mod (x , b) = 2 时, x =  2b + 2, 4b + 2, 6b + 2, ..... 2a * b…
A. Pasha and Stick 题目连接: http://www.codeforces.com/contest/610/problem/A Description Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive…
B. Vanya and Books Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/problem/B Description Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books sh…
E. Vanya and Field Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/problem/E Description Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the cell with…
C. The Big Race Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/C Description Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of…
C. Dreamoon and Sums   Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if  and , where k is some integer nu…
题目链接:http://codeforces.com/problemset/problem/334/C 题目: 题目大意: 给定数字n,要求构建一个数列使得数列的每一个元素的值都是3的次方,数列之和S大于n,且删掉数列中的任意一个元素数列之和都会小于n,最大化这个数列的长度 题解: 我们考虑从小到大枚举k,取最小的k,使得,答案就是$n/3^k+1$ 为什么呢? 我们考虑一个合法的数列,其中最小的元素是A,那么S一定是A的倍数.假设n是A的倍数,又S>n,那么S-A>=n,这样的话去掉A这个数…
链接: https://codeforces.com/contest/1228/problem/C 题意: Let's introduce some definitions that will be needed later. Let prime(x) be the set of prime divisors of x. For example, prime(140)={2,5,7}, prime(169)={13}. Let g(x,p) be the maximum possible int…
题目链接:https://codeforces.com/contest/1417/problem/B 题意 定义 $f(a)$ 为数组 $a$ 中满足: $i < j$ $a_i + a_j = T$ 的二元组 $(i,j)$ 的个数. 试将一个大小为 $n$ 的数组 $a$ 划分为 $b,c$ 两组,使得 $f(b) + f(c)$ 最小. 题解 两数之和为 $T$ 有两种情况: 一个数小于 $T$,一个数大于 $T$,此时以 $\frac{T}{2}$ 为分界线分到两组即可 两个数都等于 $…
题目链接:https://codeforces.com/contest/1363/problem/A 题意 判断是否能从 $n$ 个数中选 $x$ 个数加起来和为奇数. 题解 首先 $n$ 个数中至少需要有 $1$ 个奇数,之后为了不影响和的奇偶性向余下 $x-1$ 个数中加入成对的奇数或单个偶数即可. 代码 #include <bits/stdc++.h> using namespace std; void solve() { int n, x; cin >> n >>…
C. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to…
A. Vanya and Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 fr…
C. Tourist Problem time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are n destinations on a…
传送门 题意: 给出一个整数 n ,问能否将 n 分解成 k 个数之和,且这 k 个数必须是2的幂. 如果可以,输出"YES",并打印出任意一组解,反之输出"NO": 题解: 预备知识补充: 如何求出 num 最少需要多少个2的幂之和? 例如 : num = 3 = 20+21至少需要两个 num = 4 = 22 至少需要一个 num = 17 = 24+20 至少需要两个 根据贪心的思想 : 令 2x ≤ num,求出最大的 x ,那么此时num可以表示为 nu…
题意:从奇数列 1 3 5 7 9 ....  偶数列2 4 6 8 10...分别轮流取 1 2 4 ....2^n 个数构成新数列 求新数列的区间和 (就一次询问) 思路:首先单次区间和就是一个简单的类似前缀和就可以搞定  那么如何求新数列的和呢 我们明确一个观点:原数列的区间和结果显而易见  那么题目就转化成  奇数列和偶数列分别取了多少个数 因为取数的数字的以2的幂递增的,所以 l r(<=1e18)  log2(1e18)很简单过 而有了数量结果可以用0(1)的时间算出来 记得瞎MOD…
给予N*2个数字,改变其中的N个向上进位,N个向下进位,使最后得到得数与原来数的差的绝对值最小 考虑小数点后面的数字,如果这些数都非零,则就是  abs(原数小数部分相加-1*n), 多一个0 则 min( abs(原数小数部分相加-1*n) ,abs(原数小数部分相加-1*(n-1)) )以此类推 #include<stdio.h> int abs(int a){ )return -a; else return a; } int Min(int a,int b){ if(a<b)ret…