传送门 题意 给出n个数,计算在进行n-1次右移中\(min\sum_{i=1}^nabs(p_i-i)\) 分析 我们设置cnt[p[i]-i]为一个数p[i]与它标准位置(如1的标准位置为1)的左偏差,用L记录一个数在标准位置左边/上的个数,R为在右边的个数,关键在于n-1次移动中如何更新\(min\sum_{i=1}^nabs(p_i-i)\) 先不考虑末尾移到第一位,如果右移一位,那么有cnt[i]个元素滚到标准位置的右边了,那么L-=cnt[i],R+=cnt[i],对于答案的贡献整体…
Codeforces Round #421 (Div. 2) D. Mister B and PR Shifts 题意:给一个长度为\(n\)的排列,每次可以向右循环移位一次,计算\(\sum_{i=1}^{n}|p_i - i|\)的最小值,并求最小值是在第几次移动时取到的. 思路:我们注意到对于每个\(p_i\),其位置都取遍了\(1-n\),那么可以分成\(p_i > i\) 和 $p_i <= i $两种 对于前者 每次移动贡献-1,后者贡献+1,而且我们可以容易计算出每次移动后这两者…
传送门 题意 给出正n多边形和一个数a,寻找与a最接近的角,输出角编号 分析 找出多边形上所有角,一一比对即可 trick 1.判断的时候注意精度,i.e.x-eps>0 2.double与double相除时不要立刻转化成int,可能会有误差 代码 #include <bits/stdc++.h> using namespace std; #define ll long long #define F(i,a,b) for(int i=a;i<=b;++i) #define R(i,…
1. 819B Mister B and PR Shifts 大意: 给定排列$p$, 定义排列$p$的特征值为$\sum |p_i-i|$, 可以循环右移任意位, 求最小特征值和对应移动次数. 右移过程中维护增加的个数和减少的个数即可. #include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include <cmath> #include &…
[题目链接]:http://codeforces.com/contest/820/problem/B [题意] 给你一个正n边形; 然后让你在这正n边行中选3个点,组成一个角; 找出角的大小和所给的角最接近的角; [题解] 同弧所对应的圆周角都是相同的; 而且每个正多边行都能作出一个外接圆; 所以随便选两个相邻的点;然后再选其他 n-2个点中的一个点组成角; 就能覆盖到所有的情况了; 顺序增加角的大小就好(一份一份地加); [Number Of WA] 0 [反思] 想说是B题; 就没往复杂的地…
[题目链接]:http://codeforces.com/contest/820/problem/A [题意] 每天看书能看v页; 且这个v每天能增加a; 但是v有上限v1; 然后每天还必须往回看t页; 问你最少多少天能看完; 一共有c页; [题解] 傻逼题. [Number Of WA] 1 [反思] 在处理超过v1的时候没搞好. [完整代码] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1…
题目链接:http://codeforces.com/contest/820/problem/B 题意:给定一个正n边形,然后让你选择3个不同的顶点,使得这3个顶点形成的角度尽可能的接近a. 思路:首先模拟一下画个图发现因为是正n边形所以可以固定2个相邻的顶点然后找第3个顶点既可,这里先固定顶点1和2并且以顶点2为中点,然后枚举其他n-2个顶点计算夹角度数取最优即可.  我们知道正n边形的内角为(n-2)/n*180°,由于固定了2个相邻的顶点所以一个内角可以被划分成(n-2)份,所以每份的度数…
题目链接:http://codeforces.com/contest/820/problem/A 题意:一个人在看一本书,书一共C页,这个人每天看v0页,但是他又开始加速看这本书,每天都比前一天多看a页(就是说第一天看v0页,第二天看v0+a页,第三天看v0+2*a页...),还有一个限制一天不能看超过v1页. 然后在第二天开始每天都会回顾之前看过的l页,问你看完整本书要多少天 思路:直接按照题意模拟即可. #define _CRT_SECURE_NO_DEPRECATE #include<io…
A: 题意:给你一本书共c页,第一天看v0页,第二天看v0+a,第二天看v0+2a以此类推,每天最多看v1页,但是后一天要重复看前一天的后l页. 代码: #include<stdio.h>using namespace std;int c,v0,v1,a,l;int main(){ while(~scanf("%d%d%d%d%d",&c,&v0,&v1,&a,&l)) { int sum=v0; int k=1; while(sum…
题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次车,问最少时间到达目的地. 分析: 要使得时间最少,最后车和所有学生应该是同时到达的,我们可以观察到第一组乘车的学生和最后一组乘车的学生两者搭车时间和走路时间是相同的,那么猜想中间所有组的的学生乘车时间和走路时间是相同的(不是乘车==走路),即所有学生的乘车时间相同,走路时间相同.那么第一组学生时间…
传送门 https://codeforces.com/contest/1496/problem/B 题目 Example input 5 4 1 0 1 3 4 3 1 0 1 4 3 0 0 1 4 3 2 0 1 2 3 2 1 2 3 output 4 4 3 5 3 Note In the first test case, S={0,1,3,4}S={0,1,3,4}, a=mex(S)=2a=mex⁡(S)=2, b=max(S)=4b=max(S)=4, ⌈a+b2⌉=3⌈a+b2⌉…
A. Anton and Danik time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Anton likes to play chess, and so does his friend Danik. Once they have played n games in a row. For each game it's known…
E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to…
一 题面 C2. Increasing Subsequence (hard version) 二 分析 需要思考清楚再写的一个题目,不能一看题目就上手,容易写错. 分以下几种情况: 1 左右两端数都小于等于构造的数组的最后一个数字 2 左右两端数至少有一个大于构造的数组最后一个数字 a. 左右两端数字相等,肯定满足上面条件.那么只可能走一个方向,两边都模拟一下,比一下大小即可 b. 左右两端数组不等,则优先看谁满足上面2的情况,若都满足则选最小的 三 AC代码 #include <bits/st…
A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the…
A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When…
#include<bits/stdc++.h>using namespace std;typedef struct{ double k,b;}node;node k[1000007];bool cmp(node&a,node&b){ if(a.k==b.k)  return a.b<b.b; return a.k<b.k;}long long x[1007],y[1007];int main(){ long long n,ans=0,tot=0; scanf(&qu…
优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main() { int n; scanf("%d",&n); int t; scanf("%d",&t); ; i <= n; i++){ int v; scanf("%d",&v); q.push(v); } ; while(…
A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. Afte…
题意:有一个\(2\)X\(n\)的矩阵,你想从\((1,1)\)走到\((2,n)\),每次可以向上下左右四个方向走,但在某些时间段某个点会被堵住,如果已经被堵住,那么即恢复正常,每次对某个点操作,操作后询问是否能走到终点. 题解:只有当第一层和第二层被堵的点连通时才会到不了终点,比如\((x,y)\)和\({(x+1,y),(x+1,y-1),(x+1,y+1)}\).所以我们记录当前给的点的另外一层所对应的三个点的贡献,然后判断一下直接输出答案就好了,思路简单,具体看代码吧. 代码: in…
题意:给你一串括号,每次仅可以修改一个位置,问有多少位置仅修改一次后所有括号合法. 题解:我们用栈来将这串括号进行匹配,每成功匹配一对就将它们消去,因为题目要求仅修改一处使得所有括号合法,所以栈中最后一定会有两个括号剩余,并且这两个括号要么是\(((\)要么是\())\),\()(\)是无论如何都不合法的,对于\())\),我们去找它左边的\()\)的个数贡献给答案(因为每次修改可以使[\((++\),\()--\)],所以栈中剩余的\())\)就没有了),对于\(((\)的情况也是一样的,我们…
题意:有\(n\)本书,A和B都至少要从喜欢的书里面读\(k\)本书,如果一本书两人都喜欢的话,那么他们就可以一起读来节省时间,问最少多长时间两人都能够读完\(k\)本书. 题解:我们可以分\(3\)种情况来存,即: ​ 1.\(a=b=1\). 2.\(a=1,b=0\). 3.\(a=0,b=1\). 对于2和3来说,我们可以将他们排序,然后合并到一起,最后放到第1种情况中再排一次序,取前\(k\)个前缀和即可. 代码: int n,k; int t,x,y; int ans; vector…
题意:有两个完全相同的排列,将其中一个的元素按相对顺序插入另外一个排列中,给你操作完的排列,求原排列. 题解:感觉看看样例就能直接写了啊,直接遍历,用桶存数字个数,如果桶为空,直接输出即可. 代码: int t; int n; vector<int> v; map<int,int> mp; int main() { ios::sync_with_stdio(false);cin.tie(0); cin>>t; while(t--){ cin>>n; mp.c…
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…
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his info…
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Victor adores the sets theory. Let us remind you that a set is a group of…