首页
Python
Java
IOS
Andorid
NodeJS
JavaScript
HTML5
【
【poj3270】 Cow Sorting
】的更多相关文章
【poj3270】 Cow Sorting
http://poj.org/problem?id=3270 (题目链接) 题意 n个数要要按从小到大的顺序排列,每次只能交换任意两个数,交换的代价为这两个数之和,问最小代价. Solution 题目简单,想清楚再写..而我想清楚已经过去15分钟了→_→ 细节 如果Wa了请点开Discuss,里面有组hack数据. 代码 // poj3270 #include<algorithm> #include<iostream> #include<cstdlib> #includ…
【USACO07FEB】 Cow Relays
[题目链接] 点击打开链接 [算法] 朴素算法,就是跑N-1遍floyd 而满分算法就是通过矩阵快速幂加速这个过程 [代码] 注意要离散一下 #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cm…
【BZOJ-4422】Cow Confinement 线段树 + 扫描线 + 差分 (优化DP)
4422: [Cerc2015]Cow Confinement Time Limit: 50 Sec Memory Limit: 512 MBSubmit: 61 Solved: 26[Submit][Status][Discuss] Description 一个10^6行10^6列的网格图,上面有一些牛.花和一些矩形围栏,围栏在格子的边界上,牛和花在格子里,牛只能向下或向右走,牛也不能穿过围栏和地图边界,求每头牛它能到达的花的数量.注意栅栏不会相交 Input 第一行一个数f表示矩…
【POJ3045】Cow Acrobats(贪心)
BUPT2017 wintertraining(16) #4 B POJ - 3045 题意 n(1 <= N <= 50,000) 个牛,重wi (1 <= W_i <= 10,000),力气si (1 <= S_i <= 1,000,000,000),堆成一个竖线,risk值为每只牛上面的w之和-它的si,使它的最大值最小,输出最小值. 题解 根据数据范围也可以知道要贪心. wi和si之和小的放上面.不要漏掉最top的牛的risk值. 证明:设i,j是相邻的两只牛,…
【USACO】Cow Brainiacs
题意描述 Cow Brainiacs 求 \(n!\) 在 \(b\) 进制表示下的第一位非 \(0\) 位的数字. 算法分析 闲话 忙人自动略过 之前做过一道 \(10\) 进制表示下的题目,感觉差不多. 一开始没什么思路,就随手打了个暴力进去,结果竟然 AC 了.(只能说数据水) n=read(),b=read(); for(int i=2;i<=n;i++){ f*=i; while(f%b==0) f/=b; f%=b; } 开开心心交给 GY,结果 \(2\) 分钟之后被 Hack 了…
【poj3615】 Cow Hurdles
http://poj.org/problem?id=3615 (题目链接) 题意 给出一张有向图,求从u到v最大边最小的路径的最大边.→_→不会说话了.. Solution 好久没写Floyd了,水一发.邻接表都不用打... 代码 // poj3615 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #inclu…
【poj1985】 Cow Marathon
http://poj.org/problem?id=1985 (题目链接) 题意 求树上两点间最长距离.题目背景以及输入描述请见poj1984. Solution 树的直径. 代码 // poj1985 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> #define L…
【poj1007】 DNA Sorting
http://poj.org/problem?id=1007 (题目链接) 题意 给出m个字符串,将其按照逆序对个数递增输出. Solution 树状数组经典应用. 代码 // poj1007 #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #include<st…
【POJ3613】Cow Relays 离散化+倍增+矩阵乘法
题目大意:给定一个 N 个顶点,M 条边的无向图,求从起点到终点恰好经过 K 个点的最短路. 题解:设 \(d[1][i][j]\) 表示恰好经过一条边 i,j 两点的最短路,那么有 \(d[r+m][i][j]=min\{d[r][i][k]+d[m][k][j] \}\),等价于矩阵乘法. 这道题 K 很大,可以用快速幂加速矩阵乘法. 代码如下 #include <cstdio> #include <algorithm> #include <memory.h> us…
【POJ】1094 Sorting It All Out(拓扑排序)
http://poj.org/problem?id=1094 原来拓扑序可以这样做,原来一直sb的用白书上说的dfs............ 拓扑序只要每次将入度为0的点加入栈,然后每次拓展维护入度即可.. 我是个大sb,这种水题调了一早上.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include &…