题目大意 求从l到r的整数中长度为n的等比数列个数,公比可以为分数 首先n=1的时候,直接输出r-l+1即可 n=2的时候,就是C(n, 2)*2 考虑n>2的情况 不妨设公比为p/q(p和q互素->既约分数) 那么等比数列为 k      k*p/q     k*(p/q)^2  .....          k*(p/q)^(n-1) 因为都是整数,所以k一定可以表示为x*q^(n-1),化简数列得 x*q^(n-1)  ........     x*p^(n-1) 也就是说,假如q &l…
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据,看看有没有结论. 2 3 4 5 6 7 8 9 10 11 12 (人数) 1 2 2 3 3 3 4 4 4 4 4 (比赛数) 发现比赛数的增长成斐波那契.维护一个前缀和即可. #include <bits/stdc++.h> #define ll long long using names…
https://codeforces.com/contest/1114/problem/C 题意 给你一个数n(<=1e8),要你求出n!在b进制下的后缀零个数(b<=1e12) 题解 a在b进制下的后缀零个数? \(a=p_1^{x_1}*p_2^{x_2}*p_3^{x_3}...*p_n^{x_n}\), \(b=q_1^{y_1}*q_2^{y_2}*q_3^{y_3}...*q_n^{y_n}\) p,q为素因子,后缀零个数为min(floor(\(x_i/y_i\))) 求p在n!…
原题地址:http://codeforces.com/contest/758/problem/F F. Geometrical Progression time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output For given n, l and r find the number of distinct geometrical pro…
下午闲来无事开了一场Virtual participation 2h就过了3道水题...又跪了..这只是Div. 2啊!!! 感觉这次直接就是跪在了读题上,T1,T2读题太慢,T3还把题读错了 要是让英语老师知道我又要天天背单词背课文去了 看来英语这东西真是不能少... 这次的过的几道题都是属于比较灵活的那种题目,感觉做这种题目挺涨智商的. 题解马上补上~~…
https://codeforces.com/contest/1152/problem/C 题意 a和b,找到k,使得lcm(a+k,b+k)最小(a,b:1e9) 题解 设gcd=gcd(a+k,b+k)且\(a<b\),即(a+k)%gcd=0,(b+k)%gcd=0,(a+k)%gcd=(b+k)%gcd,a%gcd=b%gcd 移项得b%gcd-a%gcd=0,(b-a)%gcd=0 枚举b-a的因数即gcd,维护最小值 代码 #include<bits/stdc++.h> #d…
题目链接:http://codeforces.com/contest/758/problem/C 题意:给定N*M矩阵的教室,每个位置都有一个学生,Sergei坐在[X,Y],然后老师会问K个问题,对于行而言问的顺序是从第一行,第二行...第N行,第N-1行...第二行,第一行然后重复.对于列而言问的顺序都是从左到右,现在问你最后问完K个问题后,被提问的最多的同学的次数是多少,被提问的最少的同学的次数是多少,Sergei被提问的次数是多少. 思路:由于k的范围太大,所以不能一个一个模拟,考虑下循…
题目链接:http://codeforces.com/contest/758/problem/B 题意:给定n个点灯的情况,灯只有四种颜色RBGY,然后如果某个灯坏了则用'!'表示,现在要求将坏的灯(即'!'的位置)用其他新的灯来替换(新灯只有前面描述的四种颜色),并且要满足最后的灯序列每连续四个位置的灯的颜色都不一样(即分别是给定的四种颜色,顺序任意).问最后要用每种颜色的灯的数目.题目保证输入一定合法,即一定存在一个符合条件的序列 思路:因为每连续四个位置要满足颜色不一样的要求,所以我们可以…
题目链接:http://codeforces.com/contest/758/problem/A 题意:给定N个城市的福利,国王现在想让每个城市的福利都一致.问最少需要花多少钱使得N个城市的福利值都一致. 思路:找到N个城市的福利的最大值,然后所以城市按照这个最大值来补即可. 即N*max(val[i])-sigma(val[i])  [1<=i<=N] import java.io.PrintWriter; import java.util.*; public class Main { pu…
D. Ability To Convert time limit per test 1 second Cmemory limit per test 256 megabytes input standard input output standard output Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English le…
D题,给出n,k,k是n进制数,但是大于十进制时,它的表示方法仍为十进制那种,比如16进制下的15,我们可以看成就是15,或者1|5,也就是1×16+5 = 21,让你求出能表达的最小十进制数 从后面往前面贪心的取,取越多越好 证明,一个数x和[x/10]相比较,[x/10]和x表示同一个进制的话,肯定是前者比较小,因为如果x取得最小的表示后,我们可以把x最后一位直接去掉,那得到的肯定比原来的小,所以贪心是可行的. 或者dp dp[i]表示从0,i可以组成的最小十进制数是多少 dp[i] = m…
D - Ability To Convert 题目大意:给你一个数字 n 接下来再输入一个数字 w(<10^60),表示w这个数字是 n 进制的, 并且超过十进制也用数字表示,这样就有多种组合了,问你所有组合中(划分方案中)原来的 数字十进制最小是多少. 思路:网上说可以用贪心做,但是我感觉那个贪心比较奇怪,不是很理解,还是用dp靠谱. 用dp[ i ] 表示从到第 i 个数字为止,最小十进制数最小是多少. 初始状态 dp[ 0 ]=0.然后我们枚举起点向后更新. #include<bits/…
A. Holiday Of Equality time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citi…
orz一开始想不画图做这个题(然后脑袋就炸了,思维能力有待提高) 我的做法是动态规划+贪心+构造 首先把题目给的树变成一个可行的情况,同时weight最小 这个可以通过动态规划解决 dp[x]表示以x为结点的子树,它的最小weight是多少 接着我们就只需要考虑每条边增加多少就可以了,这里可以用贪心的做法 ddfs(int x, int fa, int v) 这里v是表示给x结点最大多少增量,然后慢慢加就可以,返回没用掉的增量 其实这个做法有点奇怪,应该有更简便的做法(我觉得可以直接贪心做) #…
D. Ability To Convert time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English let…
C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others. Seat…
C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others. Seat…
orz 最近被水题卡+FST,各种掉rating 题目大意 一个数s它是n进制的,但是每一位不是用'A','B'....表示的,而是用10,11等等表示的,将它还原成十进制 这种表示方法显然会产生多解,然后求所有的解中最小的那个 这题一想就是贪心,但是一开始算法写渣了,改变思路以后才A的 简单来说就是从右边开始,把尽量多的数压到一位里面,这样会使数更小 压的思路可以这么考虑 每次新加进来一个数,如果加进来以后,已经大于原来的那个数,那么就找截取一段可行的最大数 这样考虑的目的是处理前导0带来的影…
题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:http://blog.csdn.net/u014357885/article/details/46044287 */ #include <cstdio> #include <algorithm> #include <cstring> #include <iostream…
今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has a big rectangular cho…
Codeforces Round #518 (Div. 2) [Thanks, Mail.Ru!] https://codeforces.com/contest/1068 A #include<bits/stdc++.h> using namespace std; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define sqr(x) ((x)*(x)) #define pb push_back #def…
Codeforces Round #520 (Div. 2) https://codeforces.com/contest/1062 A #include<bits/stdc++.h> using namespace std; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define sqr(x) ((x)*(x)) #define pb push_back #define eb emplace_back…
Codeforces Round #506 (Div. 3) (中等难度) 自己的做题速度大概只尝试了D题,不过TLE D. Concatenated Multiples 题意 数组a[],长度n,给一个数k,求满足条件的(i,j)(i!=j) a[i],a[j]连起来就可以整除k 连起来的意思是 20,5连起来时205; 5,20连起来时520 n<=2*1e5,k<=1e9,ai<=1e9 愚蠢的思路是像我一样遍历(i,j)可能性,然后TLE,因为这是O(n^2) 可以先思考一简单问…
Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不能进行运动或比赛 可以进行运动但不能比赛 可以进行比赛但不能运动 可以进行比赛或运动 对于每天,可以根据当天的状态选择运动,比赛或休息.但不能连续两天的选择均为运动或均为比赛.求在这 \(n\) 天中最少需要休息多少天. 数据范围:\(n \leq 100\) 简要题解:令 \(f_{i,0},f_…
赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Div. 2) 题意: 给出数列a[N] 对每个子集,若 gcd(a[I1], a[I2], a[I3] ..., a[In]) > 1,则贡献为 n*gcd 求总贡献和 限制: N <= 2e5,a[i] <= 1e6 分析: 记录 num[i]数组为 i 的倍数的个数 则 gcd >=…
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate it n = int(raw_input()) s = "" a = ["I hate that ","I love that ", "I hate it","I love it"] for i in ran…
Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393…
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输出”#Color”,如果只有”G”,”B”,”W”就输出”#Black&White”. #include <cstdio> #include <cstring> using namespace std; const int maxn = 200; const int INF =…
 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256…
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard in…