
算法
阳Younger
河南大学
展开
-
LeetCode 47. 全排列 II
used[i-1],首先i>0防止used[i-1]溢出,其次当nums[i-1]==nums[i]表示可能会出现树层重复的情况(因为可能出现used[i-1]==true的情况时,只可能出现在树枝之间,不可能出现树层之间,因为树层之间只能出现一个数),如果used[i-1]==false,即在nums[i-1]结点时,所有情况已经遍历过了,那么在nums[i]结点时,应该跳过这个结点。输出:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]原创 2022-09-29 12:20:36 · 259 阅读 · 0 评论 -
HDU - 3790 最短路径问题
问题:给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费,如果最短距离有多条路线,则输出花费最少的。Input输入n,m,点的编号是1~n,然后是m行,每行4个数 a,b,d,p,表示a和b之间有一条边,且其长度为d,花费为p。最后一行是两个数 s,t;起点s,终点。n和m为0时输入结束。(1<n<=1000, 0<m<100000, s != t)Output输出 一行有两个数, 最短距离及其花费。Sa原创 2021-08-24 09:48:27 · 213 阅读 · 0 评论 -
POJ - 2236 Wireless Network
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one b原创 2021-08-20 22:05:31 · 113 阅读 · 0 评论 -
POJ - 1182 食物链
一道十分有意思的题动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述:第一种说法是"1 X Y",表示X和Y是同类。第二种说法是"2 X Y",表示X吃Y。此人对N个动物,用上述两种说法,一句接一句地说出K句话,这K句话有的是真的,有的是假的。当一句话满足下列三条之一时,这句话就是假话,否则就是真话。1)原创 2021-08-20 18:36:09 · 126 阅读 · 0 评论 -
HDU - 4768 Flyer
The new semester begins! Different kinds of student societies are all trying to advertise themselves, by giving flyers to the students for introducing the society. However, due to the fund shortage, the flyers of a society can only be distributed to a part原创 2021-08-19 10:04:10 · 157 阅读 · 0 评论 -
51Nod - 2146 分割绳子(二分)
现在有N(1 <= N <= 1000)条绳子,他们的长度分别为L1,L2,……,Ln(1 <= Li <= 10000),如果从他们中切割出K(1 <= K <= 1000)条长度相同的绳子,这K条绳子每条最长能多长?Input共有两行,第一行包含两个正整数N和K,用一个空格分割;第二行包含N个数,一次表示N条绳子的长度,两数间用一个空格分隔,每条绳子的长度的小数不超过两位。Output仅包含一个数,表示所得K条绳子的最大长度。答案四舍五入保留小数点原创 2021-08-18 09:41:35 · 192 阅读 · 0 评论 -
计蒜客 - T1258 最小新整数(贪心)
给定一个十进制正整数n(0<n<1000000000),每个数位上数字均不为0。n的位数为m。现在从m位中删除k位(0<k<m)(0<k<m),求生成的新整数最小为多少?例如:n=9128456,k=2, 则生成的新整数最小为12456。输入格式第一行t, 表示有t组数据;接下来t行,每一行表示一组测试数据,每组测试数据包含两个数字n,k。输出格式t行,每行一个数字,表示从n中删除k位后得到的最小整数。Sa...原创 2021-08-18 08:28:32 · 621 阅读 · 0 评论 -
POJ - 2299 Ultra-QuickSort
#include <iostream>#define ll long long//因为a[i]范围超过int类型,所以要用long long存储using namespace std;const int N=5e5+5;int n;ll cnt;ll arr[N],temp[N];//temp数组为过度数组void arr_add(ll arr[],int left,int mid,int right)//归并{ if(left>=right) r...原创 2021-08-17 09:21:38 · 195 阅读 · 0 评论 -
HDU - 1285 确定比赛名次(拓扑序列)
#include <bits/stdc++.h>using namespace std;const int N=510;int h[N],e[N],ne[N],in[N],idx;//in数组是存储每个数的入度int n,m;void init()//初始化{ memset(h,-1,sizeof h); idx=0;}void add(int a,int b)//链式向前星存图{ e[idx]=b,ne[idx]=h[a],h[a]=id...原创 2021-08-16 11:48:44 · 173 阅读 · 0 评论 -
HDU - 1072 Nightmare
#include <iostream>#include <queue>using namespace std;int tt,n,m;int Map[10][10];int dx[4]= {1,-1,0,0};int dy[4]= {0,0,1,-1};struct node{ int x,y; int step; int t;} pose;void bfs(){ queue<node>q; ...原创 2021-08-16 10:55:55 · 136 阅读 · 0 评论 -
POJ - 1562 Oil Deposits(BFS)
#include <iostream>#include <cstring>#include <utility>#include <queue>#define x first#define y secondusing namespace std;const int N=105;char Map[N][N];int dx[8]={1,1,1,0,0,-1,-1,-1};int dy[8]={1,-1,0,1,-1,1,-1,0}...原创 2021-08-15 08:36:35 · 144 阅读 · 0 评论 -
POJ - 1724 ROADS
#include <iostream>#include <cstring>#define inf 0x3f3f3f3f//定义inf为无穷大using namespace std;int n,idx,k,r,sum;const int N=1e4+5;int h[N],vis[N];struct node{ int u,v,w,cost;//分别用来存储原城市,目的城市,路径长度,所消耗的硬币 int next;//用来存边}arr...原创 2021-08-15 00:07:08 · 138 阅读 · 0 评论 -
51Nod - 2060 全排列
该问题可以想象成,我有一盒纸牌和一盒箱子(纸牌数量和盒子数量相等)。把纸牌放进盒子,求有多少种不同的方法。#include <iostream>using namespace std;int n,idx;int vis[15],arr[15];void dfs(int x)//x:第x个盒子{ if(x==n+1)//当所有盒子不空的时候 { for(int i=1;i<=n;i++) { ...原创 2021-08-14 17:49:34 · 160 阅读 · 0 评论 -
HDU - 2553 N皇后问题
#include <iostream>using namespace std;const int N=15;int n,cnt;int a[N],b[N],c[2*N],d[2*N],arr[N];//a,b,c,d四个数组是分别表示行,列和两条对角线,因为行,列最大为10,那么对角线数组就用2倍行,列存储void dfs(int k)//k表示行数,i表示列数{ if(k==n+1)//如果行数等于边数+1(因为当行数等于边数指的是完成皇后安置,这时候进入边数+...原创 2021-08-13 21:13:54 · 137 阅读 · 0 评论 -
OpenJ_Bailian - 4123 马走日
#include <iostream>#include <cstring>using namespace std;int t,n,m,x,y,cnt/*记录跳过的点*/,sum/*记录一共多少种情况可以跳满*/;int vis[15][15];int dx[8]= {1,2,-1,-1,1,-2,-2,2};//马走日跳的规则是日字形跳法,例如:x=1,y=2用dx[0]dy[0]来表示,x=-1,y=2用dx[2]dy[2]表示int dy[8]= {2,1,...原创 2021-08-13 20:01:58 · 193 阅读 · 0 评论 -
HDU - 1016 Prime Ring Problem
#include <iostream>#include <cstring>using namespace std;int arr[25],vis[25],n,cnt;//根据题意,0<n<20,所以开个大小为25的数组即可。bool is_Prime(int x)//判断数x是不是质数{ int k=0; for(int i=2; i<x; i++) { if(x%i==0) { ...原创 2021-08-13 17:41:59 · 134 阅读 · 0 评论 -
POJ - 1562 Oil Deposits (DFS)
Oil Deposits原创 2021-08-13 16:25:28 · 190 阅读 · 0 评论