-------ACM_算法
计算机的小粽子
2019年本科毕业于湖南大学,目前任职字节跳动
展开
-
hdu 3018 欧拉路
Problem DescriptionAnt Country consist of N towns.There are M roads connecting the towns.Ant Tony,together with his friends,wants to go through every part of the country. They intend to visit every roa原创 2017-08-09 16:38:17 · 184 阅读 · 0 评论 -
hdu 1009 贪心算法
题目 链接 http://acm.hdu.edu.cn/showproblem.php?pid=1009题意:一共有n个房子,每个房子里有老鼠喜欢吃的javabeans,但是每个房间里的javabeans的价格不一样。老鼠用m元,问m元最多可以卖多少javabeans,其中每个房间里的javabeans可以被分割。思路 : 先求单价,然后排个序就行了。(用float 貌似精度不够。。。。)#incl原创 2017-08-11 15:21:10 · 316 阅读 · 0 评论 -
hdu 2188 简单巴什博奕
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2188仍然是简单的巴什博奕#include <iostream>#include <stdio.h>#include <string.h>#include <cmath>#include <algorithm>using namespace std;int c,n,m;int main()原创 2017-08-11 10:24:45 · 193 阅读 · 0 评论 -
hdu 1846 基础巴什博奕
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1846思路: 简单的巴什博奕,如果n%(m+1)==0,则为奇异局面,后手赢,否则为先手赢。 #include <iostream>#include <stdio.h>#include <string.h>#include <cmath>#include <algorithm>using na原创 2017-08-11 10:05:42 · 199 阅读 · 0 评论 -
hdu 1754 基础线段树
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1754思路 : 比较简单的线段树,区间求最值,单点更新。 读入字符的时候,最好用字符数组保存,使用 %s读入,如果使用 %c 会T ..好像是会吃掉换行符。。#include<cstdio>#include<iostream>#include<algorithm>#defi原创 2017-08-09 19:02:23 · 206 阅读 · 0 评论 -
hdu 2094 拓扑排序
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2094拓扑排序的思想,但是不需要进行拓扑排序。如果产生了冠军,说明只有一个人一场都没有输,其他人都输了一场。否则就没有产生冠军。#include<cstdio>#include<iostream>#include<map>#define maxn 1005using namespace std;原创 2017-08-09 17:54:24 · 255 阅读 · 0 评论 -
hdu 1213 基础并查集
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1213非常基础的并查集,先假设需要n张桌子,每次合并2个集合,就减少一张桌子。#include <cstdio>#include <iostream>#define maxn 100005using namespace std;int fat[maxn],t,n,m,a,b;int find原创 2017-08-09 17:12:05 · 205 阅读 · 0 评论 -
2145: 2017湖南多校第十三场-20170723
题目链接 水题。。。。。。。。。。。绝对的水题。。。。。。。。。。。。。。。。。。。根据期望的定义直接求即可,先将概率从大到小排序,然后直接求即可。#include <stdio.h>#include<algorithm>using namespace std;bool cmp(float a,float b){ return a>b;}int main(){原创 2017-07-24 12:36:47 · 348 阅读 · 0 评论 -
2145: 2017湖南多校第十三场-20170723
G(1968):Permutation Descent Counts题目链接题目大意: 对于任一种N的排列A,定义它的E值为序列中满足A[i]>A[i+1]的数的个数。给定N和K(K<=N<=1000),问N的排列中E值为K的个数。题解: 一题简单的dp dp[x][y]表示 【1->x】的所有排列中,E值为y的个数。很明显 长度为x,且 E值为y时的序列,是由长度为x-1,且E值为y或者y-1的原创 2017-07-24 11:53:57 · 326 阅读 · 0 评论 -
51 nod 1212 基础MST
1212 无向图最小生成树N个点M条边的无向连通图,每条边有一个权值,求该图的最小生成树。直接上代码:裸的最小生成树.#include<iostream>#include<algorithm>#include<stdio.h>#include<cmath>#define max1 1005#define max2 50005using namespace std;struct edge原创 2017-07-16 19:11:51 · 208 阅读 · 0 评论 -
51nod 1134 最长递增子序列
1134 最长递增子序列给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10普通dp的时间复杂度是O(n2),肯定会超时,采用dp+二分的方法,可以优化到O(nlogn)。 例如上面的序列: i为序列下标 i=0 d[1]=5 i=1 d[1]=1 (原创 2017-07-16 00:07:51 · 189 阅读 · 0 评论 -
51 nod 1004
1004 n^n的末位数字给出一个整数N,输出N^N(N的N次方)的十进制表示的末位数字。 *求n^n的末尾数字就是求(n^n%10)的值,一个简单的公式: (n为偶数) (n为奇数)*#include<iostream>#include<stack>#include<stdio.h>using namespace std;int n;int f(int n1)原创 2017-07-15 14:23:26 · 246 阅读 · 0 评论 -
51 nod 1117 聪明的木匠 (贪心)
http://www.51nod.com/onlineJudge/submitDetail.html#!judgeId=348759思路:其实这道题反过来想,就是将其中两个数组合起来,加上它们的和就行了,贪心算法即可,每次选择两个最小值进行合并,最后结果就是答案了。#include<iostream>#include<queue>#include<stdio.h>#include<algori原创 2017-09-22 21:25:53 · 564 阅读 · 0 评论 -
51 nod 1099 任务执行顺序(贪心)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1099思路:贪心法,剩余空间最大的活动安排在前面。。即 r-o最大 的排前面。。#include<iostream>#include<cstring>#include<stdio.h>#include<algorithm>#define maxn 100005usi原创 2017-09-22 20:48:04 · 196 阅读 · 0 评论 -
hdu 2544 基础最短路
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2544基础最短路,直接用迪杰斯特拉即可(注意会输入重边).#include<stdio.h>#define MAX 0x3fffffffint map[105][105],dis[105];bool use[105];int n,m;void dijk(int start){ int原创 2017-08-11 17:43:05 · 201 阅读 · 0 评论 -
hdu 2602 简单的01背包
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2602最简单的01背包,用一维数组优化。。#include<stdio.h>#include<algorithm>#define maxn 1005using namespace std;int t,n,v;int wight[maxn];int value[maxn];int beibao原创 2017-08-11 19:11:28 · 221 阅读 · 0 评论 -
51 nod 1072 威佐夫博弈
http://www.51nod.com/onlineJudge/submitDetail.html#!judgeId=315179最简单的威佐夫博弈,直接上代码:#include<iostream>#include<cmath>#include<stdio.h>#include<algorithm>#include<stack>#include<map>#include<string>原创 2017-08-13 20:19:18 · 181 阅读 · 0 评论 -
hdu 1878 欧拉回路
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1878非常基础的欧拉回路问题,如果一个图是连通图且所有点的度数都为偶数,则可以一笔画出,否则不能一笔画出。#include<stdio.h>#define maxn 1005using namespace std;int fat[maxn],n,m,a,b,n1,dig[maxn];int fin原创 2017-08-10 10:04:42 · 145 阅读 · 0 评论 -
51 nod 1255 字典序最小的子序列
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1255思路: 分三种情况:1:栈空,直接将字母压入。2:栈非空,当前字母大于栈顶元素,栈中未出现该字母,压入栈。 3:栈非空,当前字母小于栈顶元素,栈中未出现该字母,执行循环:栈顶元素大于当前字母,且后面还存在栈顶元素,弹出栈顶元素。最后压入当前字母。#include<i原创 2017-09-24 09:47:28 · 348 阅读 · 0 评论 -
51 nod 1087 1 10 100 1000 (set)
http://www.51nod.com/onlineJudge/submitDetail.html#!judgeId=347416思路:规律题。第(i*(i+1))/2+1项是1 ,其它是0,预处理求出所有为1的项,用set记录,然后直接查询。#include<iostream>#include<cstring>#include<stdio.h>#include<set>#define m原创 2017-09-20 22:30:29 · 183 阅读 · 0 评论 -
HDU1556 color the ball (树状数组)
http://acm.hdu.edu.cn/showproblem.php?pid=1556思路:直接用树状数组即可,因为更新的是区间,所以需要更新2次。 比如更新 [1,3] ,n的大小为6,那么update(1,1)其实是更新了[1,6],所以需要将[4,6]的每个元素减一,即update(4,-1).#include<iostream>#include<stdio.h>原创 2017-09-02 19:17:04 · 193 阅读 · 0 评论 -
1004 n^n的末位数字 (快速幂)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1004思路:其实就是求(n^n)%10的值。。直接用快速幂。#include<iostream>#include<stdio.h>using namespace std;int n;int quick(int n1){ int temp=1,temp1=n%原创 2017-09-01 18:36:24 · 267 阅读 · 0 评论 -
hdu 1575 Tr A(矩阵快速幂)
http://acm.hdu.edu.cn/showproblem.php?pid=1575思路:直接用矩阵快速幂即可,(记得初始化数组,不然会wa)#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MOD 9973using namespac原创 2017-08-31 21:34:44 · 195 阅读 · 0 评论 -
hdu 1757 A Simple Math Problem(矩阵快速幂)
http://acm.hdu.edu.cn/showproblem.php?pid=1757思路:矩阵快速幂 ,通过化简,得出下面公式:所以主要的问题就是求出中间矩阵的n-9次方,设中间矩阵为A 那么A^n-9可以通过快速幂求出来,比如 A^10=A^(1010)=A^8*A^2(只需要计算5次)。核心代码:matrix matrix_quick_power(matrix a,int k)//矩阵快原创 2017-08-31 20:32:40 · 157 阅读 · 0 评论 -
51nod 1007 正整数分组
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1007就是一个简单的01背包问题。#include<iostream>#include<algorithm>#include<stdio.h>#define maxn 105#define max1 10005using namespace std;int bei原创 2017-08-16 23:03:23 · 150 阅读 · 0 评论 -
51nod 1640 天气晴朗的魔法
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1640思路:先求最小生成树,最小生成树的最大值肯定是最小的,然后再求一次最大生成树(所有大于最小生成树的最大值的边抛弃)#include<iostream>#include<algorithm>#include<stdio.h>#define maxn 100005u原创 2017-08-14 16:31:43 · 197 阅读 · 0 评论 -
51nod 1240 莫比乌斯函数
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1240#include <bits/stdc++.h>using namespace std;typedef long long LL;LL Miu( LL n ) { /// 莫比乌斯函数板子。 LL m = 1; for(LL i = 2; i *原创 2017-08-14 16:02:08 · 167 阅读 · 0 评论 -
51nod 1307 绳子与重物
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1307直接用并查集就可以了。#include<iostream>#include<cstdio>#include<cstring>#include<stack>#define maxn 50005using namespace std;int s[maxn];i原创 2017-08-14 11:20:05 · 195 阅读 · 0 评论 -
51nod 1068 Bash游戏 V3
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1068Bash游戏的变形,通过SG函数找出规律: 0 1 2 3 4 5 6 7 8 9 0 1 2 0 1 2 0 1 2 0发现n%3==0的话,就是奇异局势,则B胜,否则A胜。#include<iostream>#include<cstring>#include原创 2017-08-13 21:05:14 · 93 阅读 · 0 评论 -
51nod 1067 Bash游戏 V2
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1067Bash游戏的变形,我是通过SG函数找出规律的:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 0 1 0 1 2 3 2 0 1 0 1 0 1 2 3 2 0 1 0 1 2 3原创 2017-08-13 20:54:15 · 226 阅读 · 1 评论 -
A - Number Sequence
A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n). ##第一种解法:#include<stdio.h>int main(){原创 2017-07-17 11:43:26 · 439 阅读 · 0 评论