codeforces 8c Looking for Order】的更多相关文章

题目链接 给n个物品的坐标, 和一个包裹的位置, 包裹不能移动. 每次最多可以拿两个物品, 然后将它们放到包里, 求将所有物品放到包里所需走的最小路程. 直接状压dp就好了. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map&g…
https://vjudge.net/problem/CodeForces-8C 题意: 一个平面上放着许多东西,每个东西都有一个坐标,最开始一个人在一个起始坐标,她出发去拿东西,一次要么拿一件东西,要么拿两件东西,拿了之后必须返回起始坐标. 每次花费的时间是两个坐标距离的平方,问拿完所有的东西需要的最少的时间. 思路: 由于数据范围比较小,所以可以考虑用状压dp来写.由于每次拿东西之后都要返回起点,那么其实拿东西的顺序是没有影响的,所以利用题目给定的顺序进行剪枝,即每次进行扩展的时候都考虑在前…
题目描述 Lena喜欢秩序井然的生活.一天,她要去上大学了.突然,她发现整个房间乱糟糟的--她的手提包里的物品都散落在了地上.她想把所有的物品都放回她的手提包.但是,这里有一点问题:她一次最多只能拿两个物品,她也不能移动她的手提包.并且,因为她爱整洁的习惯,如果她拿起了一个物品,她也不能将它放在其他地方,除非放回她的手提包. Lena把她的房间划分为了一个平面直角坐标系.现在Lena给你她的手提包和每个散落的物品的坐标(当然,一开始的时候她就和手提包站在一个地方).她从坐标 $(x1,y1)$…
洛谷 Codeforces 思路 一开始想偏想到了DP,后来发现我SB了-- 考虑每个\(a_i<x\)的\(i\),记录它前一个和后一个到它的距离为\(L_i,R_i\),那么就有 \[ ans_k=\sum_{i=1}^n L_iR_{i+k-1} \] 显然把\(L\)数组翻转一下就是一个FFT了. 最后特判\(k=0\). 代码 #include<bits/stdc++.h> clock_t t=clock(); namespace my_std{ using namespace…
题目链接: B. Chat Order time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so t…
C. Looking for Order time limit per test 4 seconds memory limit per test 512 megabytes input standard input output standard output Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the Univ…
Description 题库链接 给你一个长度为 \(n\) 的序列 \(A\) ,和一个数 \(x\) ,对于每个 \(i= 0\sim n\) ,求有多少个非空子区间满足恰好有 \(i\) 个数 \(<x\) . \(1 \leq n \leq 2 \cdot 10^5\) Solution 我们用 \([A_i<x]\) 做一个前缀和,显然这是单调递增的.记前缀和为 \(i\) 的个数为 \(f_i\) . 显然对于 \(i=k,k\neq 0\) 答案就是 \[\sum_{i=0}^{…
题意:有个人想收拾行李,而n个物品散落在房间的各个角落里(n < 24).现在给你旅行箱的坐标(人初始在旅行箱处),以及n个物品的坐标,你一次只能拿最多两个物品,并且拿了物品就必须放回旅行箱,不能暂时放在地上.问最小的花费是多少?花费是笛卡尔距离的平方. 思路一看n 只有24,应该很容易想到要用状压DP. 那么dp[i]表示i状态并且回到原点的最小花费.那么就暴力枚举拿1个或两个物品放回原点,然后转移就行了.需注意,这个题目中拿物品的顺序对答案无影响,比如先拿1号,再拿2号和先拿2号,再拿1号的…
状压模板题 CF难度2000? 我得好好了解一下CF的难度机制了 反正CF的难度比洛谷真实就好了 Code #include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #define N 25 #define INF 0x3f3f3f3f using namespace std; inline int read() { int…
前言 从后往前刷 update 新增 \(\text{\color{red}{Mark}}\) 标记功能,有一定难度的题标记为 \(\text{\color{red}{红}}\) 色. 题单 (刷过的题就会登记在上面) 2B The least round way 只有 \(2^a*5^b\) 尾随'\(0\)'的个数为 \(\text{min}(a,b)\),dp一遍就好了 4D Mysterious Present 5C Longest Regular Bracket Sequence [C…
题目链接: http://codeforces.com/problemset/problem/8/C C. Looking for Order time limit per test:4 secondsmemory limit per test:512 megabytes 问题描述 Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready f…
C. Looking for Order 题目连接: http://www.codeforces.com/contest/8/problem/C Description Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess…
B. Order Book time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction…
原题链接:http://codeforces.com/contest/572/problem/B 题意 很迷,自行看题. 题解 看懂题就会做了 代码 #include<iostream> #include<cstring> #include<algorithm> #define MAX_N 100005 using namespace std; int n,s; struct exchange { public: bool ty; int p, q; double sp…
题目 传送门:QWQ 分析 这种题不会做 吃枣药丸..... 想到状压已经经过的点. 然后更新时枚举两个点加进去. 复杂度$  {O(2^n \times n^2)}$. 凉凉. 真正的做法是每一个状态只要找到一组解就break.这样可以省掉一层n. 大致上就像lrj紫书的dp例题一样,反正这个点都要选,那就先选了他. 还不是很懂这个神奇的break..... 代码 #include <bits/stdc++.h> using namespace std; , INF=1e9; <<…
解法:用l,r分别代表buy的最大值和sell的最小值,add时,若添加的值在l,r之间,则该值有可能作为下一次accept的值 accept x时,x只能在区间[l,r]中,否则无解,若x为l或r,ans不变,否则,x的类型可以是sell或buy,ans*=2,更新l,r值为x的左右值 结尾是add而没有accept时,需要维护出现在l,r之间的值得数量,这些值可以是buy或sell,ans*=(ins+1)即可 (结尾*=(ins+1)想成了+=(ins+1),记录一下自己犯的小错误,小错误…
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of bconsecutive cells. No cell can be part of two ships, however, the shi…
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's…
 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#262_1002 B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him…
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…
题目 Source http://codeforces.com/problemset/problem/717/G Description You have recently fallen through a hole and, after several hours of unconsciousness, have realized you are in an underground city. On one of your regular, daily walks through the un…
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have decided to watch the best moments of some movie. There are two buttons on your player: Watch the current minute…
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard input output: standard output Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships…
E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard input output: standard output Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are …
C. Socks time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to congratulate him, and each of them…
Codeforces Round #270 1003 C. Design Tutorial: Make It Nondeterministic time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A way to make a new task is to make it nondeterministic or probabili…
[codeforces 339]E. Three Swaps 试题描述 Xenia the horse breeder has n (n > 1) horses that stand in a row. Each horse has its own unique number. Initially, the i-th left horse has number i. That is, the sequence of numbers of horses in a row looks as foll…
[codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of…