- 博客(64)
- 资源 (1)
- 收藏
- 关注
原创 Rank HDU - 1704 (传递闭包。。)
传递闭包,三重循环,外面两层循环按照列优先来遍历,最内层循环按照行来遍历。#include <stdio.h>#include <cstring>int list[505][505];int main(){ int k; int n, m, a, b; scanf("%d", &k); while(k--) ...
2018-08-31 19:38:01 163
原创 Lotto HDU - 1342(DFS)
#include <stdio.h>#include <cstring>int n;int list[50];bool mark[50];int ans[6];void print(){ bool flag = false; for(int i = 0; i < 5; i++) //判断是否是升序排列的 i...
2018-08-31 16:24:15 132
原创 Robot Motion HDU - 1035(DFS)
#include <stdio.h>#include <cstring>#include <stack>using namespace std;char list[15][15];bool mark[15][15];int n, m, k;int dir[26][2] = {0}; int ans_s = 0; // 标记循环的步数 ...
2018-08-31 12:56:03 100
原创 Safecracker HDU - 1015-(DFS)
#include <stdio.h>#include <cstring>using namespace std;char list[15];int n;bool mark[15];char ans[6];char ans_tmp[6];int max = 0;int num[6];int pow(int x, int y) //不知道为...
2018-08-30 19:29:52 122
原创 A strange lift HDU - 1548(BFS)
#include <stdio.h>#include <cstring>#include <queue>using namespace std; struct Node{ int x; int count;};struct List{ int p[2]; //正负 }list[402]; //存贮电梯...
2018-08-30 15:55:37 74
原创 Hat’s Words HDU - 1247 (字典树)
#include <stdio.h>#include <cstring>char str[50002][110];struct Node{ Node *next[26]; int v; Node(){ v = 0; memset(next, 0, sizeof(next)); }};Node...
2018-08-30 14:47:23 77
原创 Phone List HDU - 1671(字典树)
#include <stdio.h>#include <cstring>/** 若A是B的前缀,有两种情况,一是A先建树(短的先建树),二是B先建树 (长的先建树) */ struct Node{ int length; //将字符串的长度存到叶子节点 Node *next[10]; Node(){ l...
2018-08-30 11:58:19 134
原创 Immediate Decodability HDU - 1305(字典树)
#include <stdio.h>#include <cstring>/** 若A是B的前缀,有两种情况,一是A先建树(短的先建树),二是B先建树 (长的先建树) */ struct Node { int length; Node *next[2]; Node() { length = 0; ...
2018-08-30 10:59:14 130
原创 统计难题 HDU - 1251-(字典树)
#include <stdio.h>#include <cstring>struct Node{ Node *next[26]; int count; //记录前缀的个数 Node(){ count = 0; memset(next, 0, sizeof(next)); } }; ...
2018-08-29 19:50:58 114
原创 HDU-1075-What Are You Talking About(字典树/前缀树)(已AC,之前少了一个判断条件。。。)
#include <stdio.h>#include <cstring>struct Node{ char *ch; Node *next[26]; Node(){ ch = NULL; memset(next, 0, sizeof(next)); }};Node *root = new Nod...
2018-08-29 19:05:58 160
原创 Ignatius and the Princess I HDU - 1026 (BFS-优先队列-输出路径)
#include <stdio.h>#include <algorithm>#include <functional>#include <queue>#include <cstring>using namespace std;int n, m;int dir[4][2] = {0,1, 0,-1 , 1,0 , -1,...
2018-08-29 11:21:35 128
原创 Tempter of the Bone HDU - 1010(DFS+奇偶剪枝)
本题是求是否存在一条路径,故用DFS。只用DFS会超时,因此,还需要用到求解距离问题中常用到的奇偶剪枝。奇偶剪枝请看这个博客,讲解的很透彻 https://blog.csdn.net/i1020/article/details/54918472在求解本题中,也遇到了一个大坑,就是flag变量没有初始化,导致一直wrong answer,一定要记得把所有全局变量在每输入一次就初始化一次,不...
2018-08-28 15:17:46 111
转载 Fire Net HDU - 1045-(DFS)
#include <stdio.h>#include <cstring>/* 本题要注意坐标可以用一个数来表示,p, x = p / n; y = p % n; */ char map[4][4];bool mark[4][4];int n, ans;bool Judge(int nx, int ny){ if(mark[nx][ny...
2018-08-28 10:33:04 101
原创 N! HDU - 1042(大数相乘-万进制)
/**万进制:将原来的一个大数,以4位(10000)为单位分割开,分别存到list[i]中,输出时输出按照顺序输出list[i] 即可,比如162,0838,9898 * 14list[0] = 162, list[1] = 0838, list[2] = 9898,分别求出list[i] * 14,判断结果是否大于10000,若大于10000,则要向list[i-1]进位。 */ ...
2018-08-27 14:28:50 308
原创 HDU - 1002-A + B Problem II (大数相加)
#include <stdio.h>#include <string>#include <iostream>using namespace std;string str1, str2, ans;int main(){ int n; scanf("%d", &n); getchar(); int count...
2018-08-27 12:24:27 103
原创 HDU-1020-Encoding(字符串)
#include <stdio.h>#include <cstring>struct Character{ char c; int x;}str[27];char list[10001];int main(){ int n; scanf("%d", &n); for(int i = 0; i < 26...
2018-08-26 20:16:09 146
原创 HDU-1606-Excuses, Excuses!(字符串)
这道题其实不难,但是花了很长时间才做出来,就是因为少了getchar(),做字符串类型的题的时候一定要注意,若在输入字符串之前,前面的输入会有换行,则一定要用getchar()把回车吃了。#include <iostream>#include <string>#include <algorithm>#include <stdio.h>...
2018-08-26 19:29:56 155
原创 TEX Quotes-POJ-1488 (字符串)
#include <iostream>#include <string>using namespace std;int main(){ string list; string ans = ""; int k = 0; while(getline(cin, list)) { if(k % 2 == 0) ...
2018-08-25 17:29:56 138
原创 printf()将10进制数安照输出16进制,8进制输出
printf("%x", num) //输出num的16进制数printf("%o", num) //输出num的8进制数
2018-08-25 12:05:43 2014
转载 九余定理
证明:假设,数d的根为d%9( 暂时不取0,整除时取9)当d < 10时,1~9这9个数肯定成立;当d >= 10时,d的根为d%9 = (d-1)%9+1,即d的前一个数的数根加1.得证.原博客:https://blog.csdn.net/coding_or_dead/article/details/52749128...
2018-08-25 11:24:38 541
原创 HDU-1013-digital roots
#include <stdio.h>#include <cstring>int main(){ char num[10000]; //尽量选大一些,不然会报错 while(~scanf("%s", num)) { if(strcmp(num, "0") == 0) break; ...
2018-08-25 11:20:29 111
原创 OpenJ_Bailian - 2885-计算反序数
#include <stdio.h>#include <cstring>int reverse(int x){ if(x == 0) return 0; int tmp = 0; int ans = 0; while(x != 0) { tmp = x % 10; ans = ...
2018-08-24 20:11:32 187
原创 二叉树的遍历 HRBUST - 2040
#include <stdio.h>#include <malloc.h>struct Node{ Node *lchild; Node *rchild; int x;};int n;int l1[100];int l2[100];Node *build(int s1, int e1, int s2, int e2){...
2018-08-24 17:32:19 173
原创 HDU-2037-今年暑假不AC(贪心)
#include <stdio.h>#include <algorithm>using namespace std;//贪心策略:优先选择结束时间最早的 struct Thing{ int start; int end;}list[1000];bool cmp(Thing a, Thing b){ return a.end ...
2018-08-24 13:26:30 185
原创 HDU-1009-FatMouse' Trade (贪心性价比与0/1背包的区别)
注意,本题不是0/1背包问题,因为每个物品可以拆分,而0/1背包问题每个物品不可以拆分,即也就是用不到性价比这个量#include <stdio.h>#include <algorithm>using namespace std;typedef struct Thing{ double jb, cf, jc;}Thing;bool ...
2018-08-24 13:14:07 143
原创 HDU-1425-sort-(hash思想)
#include <stdio.h>#include <cstring>#define offset 500000int hash[1000001];int main(){ int n, m; while(~scanf("%d%d", &n, &m)) { memset(hash, 0, sizeof...
2018-08-23 15:28:26 124
原创 HDU - 1862-EXCEL排序
#include <stdio.h>#include <algorithm>#include <cstring>using namespace std;struct Student{ char name[10]; int number; int sorce;}st[100000];bool cmp1(Student ...
2018-08-22 20:28:35 145
原创 OpenJ_Bailian - 2915-字符串排序
#include <stdio.h>#include <algorithm>#include <cstring>#include <string>using namespace std;struct SS{ int len; char *tmp;};bool cmp(SS a, SS b){ retu...
2018-08-22 18:51:04 143
转载 gets()与scanf("%s", s)的区别--来源于网络
二者都是从终端读入字符串,都是c中的函数(不能用他们来输入c++中string类型的),功能为1、 gets功能为读入一行,并将换行符转换为字符串结束符。2、 scanf("%s",s);读入时,遇到空白字符,包括空格,制表符,换行符时均会停止输入。从功能上可以看出不同之处:1 终止条件不同。gets只有遇到\n时才会结束输入,而scanf遇到空格或制表符时,也会结束输入。比如输入"t...
2018-08-22 18:41:33 470
原创 冒泡排序理解
n表示要排序的个数,i表示已经排好序的个数,冒泡排序每排一次,就会把未排序中最大的排到n-1-i的位置 而后面的i+1个数表示已经排好序的,在n-1-i这个位置之前的元素都没有排序,所以第二层循环j<n-1-i;所以冒泡排序排好序的元素始终在最后面,是从后往前逐渐增加的。 for(int i = 0; i &...
2018-08-22 16:37:59 752
原创 HDU - 2000-ASCII码排序
#include <stdio.h>#include <algorithm>#include <cstring>using namespace std;int main(){ char list[4]; int a, b, c; while(~scanf("%s", list)) { int h...
2018-08-22 11:54:21 147
原创 string和string.h的区别
一般来说,.h后缀都是c的头文件,与其相对应的不加.h的都是c++的头文件,比如#include <iostream.h> 和#include <iostream>,前者是c的头文件,后者是c++的头文件,也就是c++没有.h的扩展名,一般后者都是前者的升级版本。在c++标准化的过程中,为了表示头文件来源于c,有时也在前面加上c,比如cmath就来源于math.h...
2018-08-22 11:29:55 9225 5
原创 HDU - 2191-珍惜现在,感恩生活(多重背包)
#include <stdio.h>#include <algorithm>#include <cstring>#define MAX 100000000using namespace std;int dp[20001];struct bag{ int w, v, c;}bag[2000];int main(){ in...
2018-08-22 11:14:32 77
原创 HDU - 1114-Piggy-Bank (完全背包)
#include <stdio.h>#define MAX 10000000int min(int a, int b){ return a > b ? b:a;}struct Coin{ int v, w;}coin[501];int dp[10001];int main(){ int t, e, f, n; scan...
2018-08-21 17:38:03 90
原创 0-1背包问题中第二层循环为什么要倒序,完全背包问题中的第二层循环为什么又正序了
我们将一维数组看作是一条直线,并且用前面的元素值来更新后面的元素值,我们有两种选择,一是从前往后更新,二是从后往前更新,但这两种更新的效果完全不同:从前往后更新,我们选择的是根据当前的状态值来更新本次的结果,从后往前更新,我们选择的是根据上一次的状态值来更新本次的结果。0-1背包问题的状态转移方程是:f[i][j] = max(f[i-1][j], f[i-1][j - weight...
2018-08-21 15:11:04 4350 2
原创 getchar()与scanf()的理解
1.getchar()是将输入的字符都存到缓冲区中,直到输入回车(将回车也存到缓冲区中)才读取缓冲区中的字符,而且若输入了多个字符到缓冲区中,后面的字符不用按回车便会依次读取到后序的getchar()中。2.scanf()的程序片段如下: char a, b, c, d; scanf("%c", &a); scanf("%c", &b); ...
2018-08-21 11:09:37 1307
转载 HDU - 1864-最大报销额(0-1背包)
#include <stdio.h>#include <algorithm>#include <vector>#include <cstring>using namespace std;double dp[3000000];int main() { double Q; int m, k; while(~scan...
2018-08-20 19:54:33 102
转载 HDU-1503-Advanced fruits(最长公共子序列)
#include <stdio.h>#include <algorithm>#include <string.h>using namespace std;char str1[101];char str2[101];int dp[101][101];char tmp[101];int main(){ //这里输入的时候将str1和...
2018-08-20 15:55:33 142
原创 coincidence-(最长公共子序列)
#include <stdio.h>#include <algorithm>#include <string.h>using namespace std;//注意sizeof和strlen的区别 char a[100];char b[100];int dp[100][100];int main(){ while(~scanf(...
2018-08-20 10:58:22 143
Udec600_64bit323.msi
2020-04-26
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人