Codeforces 121A Lucky Sum】的更多相关文章

Lucky Sum Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 121A64-bit integer IO format: %I64d      Java class name: (Any)     Petya loves lucky numbers. Everybody knows that lucky numbers are positive…
Description Lucky Sum time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation c…
题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/20076297 题目大意:给出一个n,ans = ∑(2≤i≤n)1/(v(i)*u(i)), v(i)为不大于i的最大素数,u(i)为大于i的最小素数, 求ans,输出以分式形式. 解题思路:一開始看到这道题1e9,暴力是不可能了,没什么思路,后来在纸上列了几项,突然想到高中时候求等差数列时候用到…
codeforces 963A Alternating Sum 题解 计算前 \(k\) 项的和,每 \(k\) 项的和是一个长度为 \((n+1)/k\) ,公比为 \((a^{-1}b)^k\) 的等比数列. 当公比为 \(1\) 时,不能用等比数列求和公式. 什么时候公比为 \(1\) ? 当 \(a=b\) 时,\(a^{-1}b=1(mod\ p)\) 当 \(a=p-b\) 时,\(a^{-1}b=(p-b)^{-1}b=-1(mod\ p)\),如果此时 \(k\) 是偶数,公比就…
codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 单点修改 询问区间内最小的unbalanced number balanced number定义是,区间内选取数字的和sum sum上的每一位都对应着选取的数上的一位 否则就是unbalanced number 题解: 根据题意 如果区间存在unbalance number,那么一定存在两个数就可…
Lucky Ticket Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 146A Description Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal…
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits \(4\) and \(7\). For example, numbers \(47\)…
http://codeforces.com/problemset/problem/577/B 题意:有n个数,求有无一个子序列满足和是m的倍数 思路:用模下的背包做,发现n是十的六次方级别,但是有个神奇的性质,就是抽屉原理,当n大于等于m的时候,总会有sum[i]和sum[j]满足sum[i]%m=sum[j]%m,于是当n>=m的时候就可以特判掉,DP的复杂度就是O(n^2)的 总结:一定要记住,在模m下的前缀和这样的东西,一定要记得有抽屉原理! 然后这题的XX细节真是坑死我了 #includ…
题目链接:http://codeforces.com/contest/85/problem/D 做法果然男默女泪啊..... 大概就是直接开了一个$vector$每次插入删除都用自带的$insert$和$erase$,然后查询也是暴力搞. 那么为啥么过得很有理有据呢? 1.首先考虑如果没有修改我就能继承上一次的答案... 2.修改我们假设(就是)${O(logn)}$的. 3.每次暴力查询是$5$个数字一步. 4.显然一开始并不是上来就有${100000}$个数字 所以大概复杂度会是${O(n^…
B. Odd sum 题目链接:http://codeforces.com/problemset/problem/797/B time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given sequence a1, a2, ..., an of integer numbers of length n. Your ta…
题目链接:http://codeforces.com/problemset/problem/963/A 题目大意:就是给了你n,a,b和一段长度为k的只有'+'和‘-’字符串,保证n+1被k整除,让你你计算. 解题思路: 暴力肯定超时的,我们可以先计算出0~k-1这一段的值,当做a1,可以发现如果把每段长度为k的段的值当做一个元素,他们之间是成等比的,比值q=(b/a)^k, 然后就直接用等比数列求和公式求出答案即可.昨天把q当成b/a了,我的脑子啊... 注意,判断q==1时不能通过判断a==…
一.题目 二.题目链接 http://codeforces.com/contest/920/problem/F 三.题意 给定$N$个范围在$[1, 1e6)$的数字和$M$个操作.操作有两种类型: $1$ $l$ $r$:更新区间$[l$, $r]$的数字ai为d[ai].其中d[i]表示数字i的因子的个数.如:d[1] = 1, d[2] = 2, d[3] = 2, d[4] = 3. $2$ $l$ $r$:查询区间$[l, r]$的数字和并输出. 四.思路 典型的数据结构题.很明显这是…
D. Sum of Medians Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/85/D Description In one well-known algorithm of finding the k-th order statistics we should divide all elements into groups of five consecutive el…
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has an array consisting o…
传送门: http://codeforces.com/problemset/problem/598/A A. Tricky Sum time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In this problem you are to calculate the sum of all integers from 1 to n, b…
题目链接:http://codeforces.com/problemset/problem/448/C 题意: 给你n个数字,给定m. 问你是否能从中选出若干个数字,使得这些数字之和为m的倍数. 题解: 其实就是要找一些数字,使得之和mod m为0. 开一个vector,存当前已经能够构成的数字之和mod m之后的值. 一开始vector为空,然后枚举n个数字a[i],对于每个数字枚举当前vector中的值v[i],将没有出现过的(a[i]+v[i])%m值加入vector中. 最后判断下vec…
[题目链接]:http://codeforces.com/problemset/problem/257/D [题意] 给你n个数字; 这n个数字组成的数组满足: a[i-1]<=a[i]<=2*a[i-1] 让你确定每个数字的符号(正或负); 然后把所有的数字都加起来; 把和记为s; 需要满足0<=s<=a[1]; [题解] 记最后一个数字的符号为+ 然后sum=a[n] 由a[i]<=2*a[i-1] 可以得到 a[i]-a[i-1]<=a[i-1] 则让sum去减a…
题目描述: The Sum of the k-th Powers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees. Find th…
F. SUM and REPLACE time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Let D(x) be the number of positive divisors of a positive integer x. For example, D(2) = 2 (2 is divisible by 1 and 2), D(6) …
D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output In one well-known algorithm of finding the k-th order statistics we should divide all elements into groups of five consecu…
题目链接:http://codeforces.com/problemset/problem/577/B 题目意思:就是给出 n 个数(a1, a2, ..., an) 和 m,问能不能从这 n 个数中选出一些数(不能为空),使得这些数的总和能整除 m . 实不相瞒,完全没想法...看题解,有个地方看都看不懂: n > m的情况.求助乌冬子,连带被批英语水皮 >___<.还是谢谢他啦,一步一步引导我. 貌似挺多人也有这个疑惑的.他说那个是特例优化,原谅我懒,直接摘抄吧~ 首先要知道一些参数…
C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard input output standard output The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a num…
E. Lucky Queries time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains…
题意: 一个数只含有4,7就是lucky数...现在有一串长度为n的数...问这列数有多少个长度为k子串..这些子串不含两个相同的lucky数... 子串的定义..是从这列数中选出的数..只要序号不同..就不不同的串..如 1 1 的长度为1的子串有两个 题解: 解题前可以先求一下1000000000内有多少个数是lucky的...可以递推的求..也可以暴力求~~可以看出最多1022个lucky数..很少... 现将这堆数的所有lucky数找出来...把相同的放在一个lucky数里计数... d…
题目链接:http://codeforces.com/contest/598/problem/A 题目分类:大数 题意:1到n 如果是2的次方则减去这个数,否则就加上这个数,求最后的结果是多少 题目分析:数很大,关键是精度问题,刚开始用__int64和double发现都是不对的,后来发现用long long 可以过 代码: #include<bits/stdc++.h> using namespace std; #define LL long long LL a[]={,,,,,,,,, ,,…
630C - Lucky Numbers 题目大意: 给定数字位数,且这个数字只能由7和8组成,问有多少种组合的可能性 思路: 假设为1位,只有7和8:两位的时候,除了77,78,87,88之外还哇哦加上前面只有7和8的情况,一共是6位.所以递推式不难写出dp[i]=pow(2,i)+dp[i-1]; 代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; ll ans[56]; void init ()…
Mitya has a rooted tree with nn vertices indexed from 11 to nn, where the root has index 11. Each vertex vv initially had an integer number av≥0av≥0 written on it. For every vertex vv Mitya has computed svsv: the sum of all values written on the vert…
我们先把问题分成两部分, 一部分是把元素往前移, 另一部分是把元素往后移.对于一个 i 后的一个位置, 我们考虑前面哪个移到这里来最优. 我们设最优值为val,   val = max(a[ j ] * (i - j) - (sum[ i ] - sum[ j ]) 我们能发现这个能转换成斜率优化的形式如果 j 比 k 更优且 j > k 我们能得到, ((j * a[ j ] - sum[ j ])  - (k * a[ k ] - sum[ k ]))  < i *  (a[ j ] -…
Lucky Queries 感觉是很简单的区间合并, 但是好像我写的比较麻烦. #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…
题目描述 Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has sequence aa co…