C. Do you want a date? time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immedi…
codeforces.com/contest/810/problem/C [题意] 给定一个集合A,求 , 输入: [思路] 基数为n的集合有2^n-1个非空子集. 首先n个数要从小到大排序,枚举最后的集合中最大和最小的元素是a[i]和a[j](i< j); 则f值是a[j]-a[i]的集合有2^(j-i-1)个; 然后答案+=(a[j]−a[i])*2^(j-i-1); 这样时间复杂度是O(n^2). 我们可以把各项组合一下,把2^i提取出来. 比如考虑系数为 2^1的 必然是 a[3]-a[…
[题目链接]:http://codeforces.com/contest/810/problem/C [题意] 给你一个集合,它包含a[1],a[2]..a[n]这n个整数 让你求出这个集合的所有子集a的f(a)和 这里的f(a)=集合a中最大和最小元素的差; [题解] 朴素的想法是; 将数组a升序排; 枚举最后的集合中最大和最小的元素是a[i]和a[j](i< j); 则f值是a[j]-a[i]的集合有2^(j-i-1)个; 即a[i+1]..a[j-1]这些元素选和不选-. 然后答案+=2(…
E. Sum of Remainders 题目连接: http://www.codeforces.com/contest/616/problem/E Description The only line contains two integers n, m (1 ≤ n, m ≤ 1013) - the parameters of the sum. input The only line contains two integers n, m (1 ≤ n, m ≤ 1013) - the para…
数学so奇妙.. 这题肯定会有一个循环节 就是最小公倍数 对于公倍数内的相同的数的判断 就要借助最大公约数了 想想可以想明白 #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> #include<vector> using namespace std; #define N 1000100 #defin…
The least round way 题目链接:http://codeforces.com/contest/2/problem/B ——每天在线,欢迎留言谈论.PS.本题有什么想法.建议.疑问 欢迎留言!! 题目大意: ①第一行给你一个n,表示接下来将给你一个n阶方阵的数据 ②要求你从左上方出发到右下方,路径上所有数字乘积 的末尾0的个数最少 ③输出最少0的个数,并输出路径 PS:①每次只能向右或向走 ②D表示向下走,R表示向右 ③0乘任何数的结果 末尾都是一个0: 知识点: ①多个数字相乘,…
C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n−2n−2 intermediate planet…
http://codeforces.com/problemset/problem/586/C 题意:1~n个孩子排成一排看病.有这么一个模型:孩子听到前面的哭声自信心就会减弱:第i个孩子看病时会发出v[i]的叫声,他后面的那个人的自信心(不是p[i+1])会减少v[i],再后面一个会减少v[i]-1,如此下去直到声音减弱为0.若某个人的自信心小于0,则他哭着跑回家,他身后的所有人会减掉d[i] 的自信. 题解:直接模拟很困难,有一个想法是将逃跑的孩子的声音和将他吓跑的(正在接诊的)声音叠加成s,…
B. Jumping Jack 题目连接: http://www.codeforces.com/contest/11/problem/B Description Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has d…
[题目]B. Recover the String [题意]找到一个串s,满足其中子序列{0,0}{0,1}{1,0}{1,1}的数量分别满足给定的数a1~a4,或判断不存在.数字<=10^9,答案<=10^6. [算法]数学构造 [题解]首先由a1和a4易得0的数量x0和1的数量x1. 容易发现01和10关系密切,令1的位置为b1...bx1,则: {0,1} (b1-1)+(b2-2)+(b3-3)+...+(bx1-x1)=a2 {1,0} (x0-b1+1)+(x0-b2+1)+...…
C. Digital Root 题目连接: http://www.codeforces.com/contest/10/problem/C Description Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1, N], and it was asked to check whether the equat…
A. Secrets Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/333/problem/A Description Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has…
题目链接:http://codeforces.com/problemset/problem/590/A 题目大意是给一个串,头和尾每次变换保持不变. 中间的a[i]变成a[i-1],a[i],a[i+1]的中位数,而且此题串是01串. 对于01串 0 0 0中位数是0 0 0 1中位数是0 0 1 1中位数是1 1 1 1中位数是1 所以 1.串中有两个相邻以上的0或者1是保持不变的. 2.会变的只有是两个1中间的0或者两个0中间的1. 但是到这里的话,虽然证明了肯定能变成稳定态,就算把相同数字…
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the…
C. Do you want a date? time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immedi…
题目链接:http://codeforces.com/problemset/problem/55/D 题意:一个美丽数就是可以被它的每一位的数字整除的数. 给定一个区间,求美丽数的个数. 显然这是一道数位dp,就是满足一个数能被所有位数的lcm整除即可. 一般都会设dp[len][mod][LCM],mod表示余数,LCM表示前len位的lcm. 但是如果直接裸mod会很复杂,于是再想lcm{0,1,2,3,4,5,6,7,8,9}=2520; 而且lcm{a,b,c,d....}{a,b,c,…
题目链接:http://codeforces.com/problemset/problem/264/B 题意:给出一个严格递增的一串数字,求最长的相邻两个数的gcd不为1的序列长度 其实这题可以考虑一下素因数,将每一个数都已是分解为几个不重复的素数,设dp[i]为含有因数i的最长序列有多长 然后遍历一下这串数字,每次更新dp[a[i]]=max(dp[j]+1,dp[a[i]]),j表示a[i]的素因数,再将每个素因数更新为 最大值. for(int i = 1 ; i <= n ; i++)…
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2). DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ...,…
题意:给定n个坐标,问你所有点离哪个近距离和最短. 析:中位数啊,很明显. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring>…
题目链接: A. Ryouko's Memory Note time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to r…
题意就是给你一个1到n的范围 你每次可以问这个数是否可以被某一个数整除 问你要猜多少数才能确定这个数…… 一开始一点思路也没有 后来查了一下才知道 每个数都可以分为几个质数的整数次幂相乘得到…… #include<stdio.h> #include<iostream> #include<algorithm> #include<math.h> #include<string.h> #include<string> #include<…
ZS and The Birthday Paradox 感觉里面有好多技巧.. #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, int> #define SZ(x…
B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output You are given a multiset of n integers. You should select exactly k of them in a such way that the difference b…
C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as…
Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number! The only thing Mrs. Smith remembered was that any permutation of nn can be a secret phone number. Only those permutations that minimize secret value migh…
题目链接: D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals t…
题目链接: D. As Fast As Possible time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output On vacations n pupils decided to go on excursion and gather all together. They need to overcome the path with th…
题意: 给定n个不重复的数, 求出这些数的所有子集, 然后设一个数Ni 为 第i个子集中,最大的数 - 最小的数. 然后将i个 Ni求和, 结果mod 1e9 + 7. 分析: 首先将n个数排列,生成一个单调的数列. 举个例子, 如 1 3 5 7 9. 可以看出 1 作为一个子集中最小的数会有 2^4 - 1 = 15种(1 和 3 5 7 9组合, 3 5 7 9任意的非空子集有2^4 - 1种) , 作为最大的数有2^0 - 1 = 0(因为没有数比1小). 同理 9 作为一个子集中最小的…
本题应该是可以使用实数二分的,不过笔者一直未调出来,而且发现了一种更为优美的解法,那就是逆推. 首先,不难猜到在最优解中当飞船回到 111 号节点时油量一定为 000, 这就意味着减少的油量等于减少之前的油量,即 fuel=mb1−1fuel=\frac{m}{b_{1}-1}fuel=b1​−1m​ 我们还可以将起飞和降落视为同一种操作,将公式进行变换,就得到 : fuel′=ai∗fuel+mai−1fuel'=\frac{a_{i}*fuel+m}{a_{i}-1}fuel′=ai​−1a…
题目传送门 传送门 群除我均会猜结论/找规律,sad.... 以下内容只保证代码能过system test,证明应该都是在纯口胡 约定下文中的$LIS$表示最长不下降子序列. 定义$zero(s)$表示串$s$中0的个数,$one(s)$表示$s$中1的个数. 约定字符串的下标从1开始.$s_{l, r}$表示$s$的$l$个字符开始到第$r$个字符组成的子串. 定义一个串$s$是fixed string,当且仅当满足下面任意一个条件: $s$是一个空串 $s = 1t0$, 并且$t$是一个f…