- 博客(21)
- 收藏
- 关注
原创 |算法讨论|贪心算法 学习笔记
选择不相交区间int end = -1, cnt = 0;//end 是上一选择区间的结束点,cnt为选择的区间个数 sort(A,A+n);//按照b排序 for(int i=0;i<n;i++)//循环每个区间 { if(end < A[i].a) //如果区间不相交 {
2016-11-27 10:56:10 392
原创 |洛谷|分治|P2799 国王的魔镜
https://www.luogu.org/problem/show?pid=2799判断整个字符串是否对称,如果对称,那么从中间分开继续比较。注意,当当前总长度为奇数时,直接退出,因为镜子不会把项链变为奇数长#include#include#includeusing namespace std;#define ms(i,j) memset(i, j, sizeof i);i
2016-11-27 10:51:05 652
原创 |洛谷|贪心|P1958 上学路线_NOI导刊2009普及(6)
https://www.luogu.org/problem/show?pid=2637把出价从小到大排序,然后从小到大枚举,把每个出价当做卖价,最后和ans比较即可#include#include#includeusing namespace std;#define ms(i,j) memset(i, j, sizeof i);int n,m;int a[1005];int
2016-11-27 10:48:23 592
原创 |洛谷|搜索|P1958 上学路线_NOI导刊2009普及(6)
https://www.luogu.org/problem/show?pid=1958深搜搜索路径条数即可,注意方向#include#include#include#includeusing namespace std;#define ms(i,j) memset(i, j, sizeof i);const int dx[2] = {1,0};const int dy[2
2016-11-27 10:46:40 587
原创 |洛谷|搜索|P2666 Bessie的秘密牧场
https://www.luogu.org/problem/show?pid=2666直接搜索即可。#include#include#include#includeusing namespace std;#define ms(i,j) memset(i, j, sizeof i);int n;int ans = 0;int dfs(int a, int s)//选第a个,已
2016-11-27 10:45:20 1003
原创 |洛谷|搜索|P2089 烤鸡
https://www.luogu.org/problem/show?pid=2089搜索即可。数组要开大一点#include#include#includeusing namespace std;#define ms(i,j) memset(i, j, sizeof i);int n = 1;int ans = 0;int map[10005][15];int h[15]
2016-11-27 10:44:20 572
原创 |洛谷|数学|P2415 集合求和
https://www.luogu.org/wiki/show?name=%E9%A2%98%E8%A7%A3+P2415可以发现集合中的元素在所有子集中出现了2^n次,算出总和*2^n即可,但要处理重复,最终答案要除以二#include#include#includeusing namespace std;#define ms(i,j) memset(i, j, sizeof i
2016-11-27 10:43:03 659
原创 |洛谷|模拟|P1184 高手之在一起
https://www.luogu.org/problem/show?pid=1184用个map搞定。注意要getline#include#include#include#include#include#includeusing namespace std;#define ms(i,j) memset(i, j, sizeof i);int n,m;map s;stri
2016-11-27 10:40:21 666
原创 |洛谷|模拟|P1146 硬币翻转
https://www.luogu.org/problem/show?pid=1146由样例可得,翻转第i次时,第i个硬币不翻,显然最小次数即为n#include#include#includeusing namespace std;#define ms(i,j) memset(i, j, sizeof i);int n;int f[105];int main(){
2016-11-27 10:38:37 608
原创 |洛谷|模拟|P2689 东南西北
https://www.luogu.org/problem/show?pid=2689由题意显然只用朝两个方向走,确定下来这两个方向以后,比对每个时刻的风向即可#include#include#include#includeusing namespace std;#define ms(i,j) memset(i, j, sizeof i);int x1,x2,y1,y2,T;
2016-11-27 10:35:25 682
原创 |洛谷|二分|P1678 烦恼的高考志愿
https://www.luogu.org/problem/show?pid=1678二分找上下界即可#include#include#include#define ms(i,j) memset(i,j, sizeof i);/* NOIP2016倒计时,RP++ Luogu: P1678 烦恼的高考志愿*/using namespace std; int m,n;in
2016-11-17 20:46:01 724
原创 |洛谷|搜索|NOIP2012|P1078 文化之旅
https://www.luogu.org/problem/show?pid=1078直接搜就好,倒搜可以过最后一个点不超时#include#include#includeusing namespace std;#define ms(i,j) memset(i,j,sizeof i);int n;//国家总数 int k;//文化总数 int m;//道路总数 int s,
2016-11-16 21:56:45 660
原创 |洛谷|贪心|P1376 机器工厂
https://www.luogu.org/problem/show?pid=1376简单的贪心,居然之前还想不到。。感觉快完了#include#include#include#define ms(i,j) memset(i,j, sizeof i);/* NOIP2016倒计时,RP++ Luogu: P1376 机器工厂*/using namespace std; i
2016-11-15 21:37:22 439
原创 |洛谷|贪心|P2813 母舰
https://www.luogu.org/problem/show?pid=281390分程序,TLE第一个点把两个数组从小到大排序,然后尽量用我方较为小的系统去打敌人较大的系统#include#include#include#define ms(i,j) memset(i,j, sizeof i);/* NOIP2016倒计时,RP++ Luogu: P28
2016-11-14 21:41:26 502
原创 |洛谷|贪心|P1413 坚果保龄球
https://www.luogu.org/problem/show?pid=1413把僵尸按照t为关键字从小到大排序,t相同时p为关键字然后用a数组来存储每一道最早能拦截到的一个僵尸的编号如果道一样,当前僵尸出现时间-之前的僵尸>=60说明这一个坚果拦不到,要增加一个#include#include#include#define ms(i,j) memset(i,j, si
2016-11-13 20:50:30 895
原创 |洛谷|动态规划|P1757 通天之分组背包
https://www.luogu.org/discuss/show?postid=2772简单分组背包#include#include#include#include#define ms(i,j) memset(i,j, sizeof i);/* NOIP2016倒计时,RP++ Luogu: P1757 通天之分组背包*/using namespace std;
2016-11-13 15:40:38 501
原创 |洛谷|动态规划|P1130 红牌
https://www.luogu.org/problem/show?pid=1130比较简单的DP,注意不能往i-1的方向换#include#include#include#include#define ms(i,j) memset(i,j, sizeof i);/* NOIP2016倒计时,RP++ Luogu: P1130 红牌*/using namespace s
2016-11-13 12:01:23 604
原创 |洛谷|动态规划|P1968 美元汇率
https://www.luogu.org/problem/show?pid=1968设f[i][0]为换美元,f[i][1]为换马克,易得出状态转移方程。#include#include#include#include#define ms(i,j) memset(i,j, sizeof i);/* NOIP2016倒计时,RP++ Luogu: P1968 美元汇率*/
2016-11-08 22:06:52 812
原创 |洛谷|动态规划|P2690 接苹果
https://www.luogu.org/problem/show?pid=2690比较简单的DP,但我还是交了3次才AC,能力仍然不足啊#include#include#include#include#define ms(i,j) memset(i,j, sizeof i);/* NOIP2016倒计时,RP++ Luogu: P2690 接苹果 设f[i][j]
2016-11-06 22:31:32 771
原创 |洛谷|动态规划|P1359 租用游艇
https://www.luogu.org/problem/show?pid=1359挺简单的一道区间DP,注意半矩阵的读入#include#include#include#include#define ms(i,j) memset(i,j, sizeof i);/* NOIP2016倒计时,RP++ Luogu: P1359 租用游艇 设f[i]为到达第i个出租站的最小
2016-11-05 22:54:35 814
原创 |洛谷|并查集|P1525 关押罪犯
https://www.luogu.org/problem/show?pid=1525先按权值从大到小排序边然后依次使边的两个点分开#include#include#include#include#define ms(i,j) memset(i,j, sizeof i);using namespace std;struct ed{ int x,y,v;}edge[1
2016-11-02 21:46:51 505
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人