http://codeforces.com/contest/1294/problem/B 大致题意: 一张图上有n个包裹,给出他们的坐标,一个机器人从(0,0)出发,只能向右(R)或向上(U),问能否收集到所有包裹,如果能,给出字典序最小的路径. 最开始当成搜索题了,其实可以排序+贪心写的. #include <stdio.h> #include <string.h> #include <iostream> #include <string> #includ…
题目大意: 机器人从(0,0)开始,他只能往上'U'或者往右'R'走 坐标系中有着很多包裹,分别在一些点上 机器人需要走过去把这些包裹全部收集起来 问能不能做到 如果能,再输出移动方式,相同移动方式输出字典序最小的方案 解题思路: pair或者结构体排序,x与y的优先级任意,因为下一个包裹必定在当前机器人位置右方/上方/右上方 否则直接输出NO,表示不可能存在这种移动方式 在输出移动方式时,注意能先用'R'就用'R',因为'U'的字典序比'R'大(即先右再上) 按照上述模拟即可 /* Writt…
BZOJ_4010_[HNOI2015]菜肴制作_拓扑排序+贪心 Description 知名美食家小 A被邀请至ATM 大酒店,为其品评菜肴. ATM 酒店为小 A 准备了 N 道菜肴,酒店按照为菜肴预估的质量从高到低给予 1到N的顺序编号,预估质量最高的菜肴编号为1.由于菜肴之间口味搭配的问题, 某些菜肴必须在另一些菜肴之前制作,具体的,一共有 M 条形如“i 号菜肴‘必须’ 先于 j 号菜肴制作”的限制,我们将这样的限制简写为<i,j>.现在,酒店希望能求 出一个最优的菜肴的制作顺序,使…
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; ; ull base[maxbit], n, k; void preDeal() { ] = ; ; i < maxbit; i++){ *]; } } voi…
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的货币越优.如有1,2,5,10,20,50,那么我们尽量用面值为1的.如果我们把原始货币换成面值为x的货币,设汇率为d,那么需要的原始货币为dx的倍数.显然dx越小,剩下的钱,即n取模dx会尽量小. 然后就可以枚举换某一种货币的数量,时间复杂度\(O(\frac{n}{d})\) 代码 #inclu…
Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water. The only dry land there is an archipelago of n narrow islands located in a row. For more comfort l…
题目大意: 给定集合,对于任意一个的排列,记,求. 很明显每次搞出一个长度为的最长上升序列,然后把元素给删掉,答案增加. 直接暴力需要. 但是可以进行优化. 设有个,将个数从小到大排序,记为长度为的数组. 则答案为 于是可以优化到. #include <cstdio> #include <cctype> #include <algorithm> using namespace std; const int T=1001; int n; int a[T],len; inl…
E. Selling Souvenirs time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an op…
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected. You should assign labels to all vertices in such a way that: Labels form a valid pe…
题目链接 Paint Tree 给你一棵n个点的树和n个直角坐标系上的点,现在要把树上的n个点映射到直角坐标系的n个点中,要求是除了在顶点处不能有线段的相交. 我们先选一个在直角坐标系中的最左下角的点,把根结点放到这个点中,然后对剩下的点进行极角排序,按逆时顺序一个个塞进来,类似地递归处理. 这样就满足了题意. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b…