Lucky Sorting(CodeForces-109D)【思维】】的更多相关文章

题意:给出一组数,要求从小到大排序,并且排序的过程中,发生交换的两个数至少一个为幸运数(十进制位均为4或7),问能否在(2×n)次交换内完成排序,如果能,输出交换的方案(不要求步骤数最少). 思路:首先分为两种情况: 1.所有的数均不为幸运数,则如果给出的序列已经排好序,答案为0,如果未排好序,则无法完成排序. 2.存在幸运数,可得,只要存在幸运数,就一定能在2×n次以内完成排序. <1>具体的处理方法是将序列分为若干个闭环,闭环的意思可以举个例子来看,(xio表示下标为xi的元素排序后所在位…
早起一水…… 题意看着和蓝桥杯B组的大题第二道貌似一个意思…… 不过还是有亮瞎双眼的超短代码…… 总的意思呢…… 就是最长增长子序列且增长差距为1的的…… 然后n-最大长度…… 这都怎么想的…… 希望今天的省选可以亮光乍现~~~ #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<math.h> using namespace s…
Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty). You may perform the following operations until both a and s are empty: Take the first element of a, push it into s and remove it from a (if a is not…
Squats Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster e…
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the numbe…
https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间的最少边数,求加边之后任意两点长度之和 思路 一看到求任意两点,知道需要用每条边的贡献计算(每条边使用了多少次) 每条边的贡献等于边左边的点数*边右边的点数 然后就一直不知道怎么解决加边后的问题,不知道要标记哪些东西,怎么减去 单独看一条路径,加边之后, 假如边数是偶数的话,边数/2 假如边数是奇数…
https://codeforces.com/problemset/problem/353/D 大意:给定字符串, 每一秒, 若F在M的右侧, 则交换M与F, 求多少秒后F全在M左侧 $dp[i]$为位置$i$处的$F$复位所花费时间, 有 $dp[i] = max(dp[i-1]+1,cnt_i)$, $cnt_i$为前$i$位$M$的个数 $dp$最大值即为答案 #include <iostream> #include <algorithm> #include <cstd…
Cards Sorting 思路: 线段树: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 100005 #define INF 0x3f3f3f3f #define maxtree maxn<<2 int n,ai[maxn],val[maxtree],L[ma…
http://codeforces.com/contest/121/problem/E 话说这题貌似暴力可A啊... 正解是想出来了,结果重构代码,调了不知道多久才A 错误记录: 1.线段树搞混num(节点编号)和l(区间端点) 2.之前的dfs没有分离,写的非常混乱,迫不得已重构代码 #include<cstdio> #include<algorithm> #include<cstring> #include<vector> using namespace…
题目链接:https://codeforces.com/gym/102012/problem/I 题意:问有多少个 1 到 n 的排列,使得用给定的 k 个比较器(使 au 和 av 有序)排序后,整个序列的最长上升子序列为 n - 1. 题解:先处理出全部最长上升子序列为 n - 1 的排列,然后枚举每个比较器使用与否,计数即可.(题目卡常,dfs要加引用...) #include <bits/stdc++.h> using namespace std; #define ll long lo…