
算法
qq_38876046
这个作者很懒,什么都没留下…
展开
-
求a^n的尾数
1.普通方法:#includeusing namespace std;int main(){ int a,n; cin>>a>>n; int i=0; int num=0; int a1=a; a=a%10; while(num<n-1) { a=a*a1; while(a>=10) a%=10; num++; } cout<<"a="<<a<<end原创 2017-10-21 14:29:58 · 284 阅读 · 0 评论 -
回溯法应用——背包问题
题目描述:假设我们有n件物品,分别编号为1, 2...n,有一个背包,它能够承载的重量是W。其中编号为i的物品价值为vi,它的重量为wi。现在,我们希望往包里装这些物品,使得包里装的物品价值最大化,那么我们该如何来选择装的东西呢?#include <iostream>#include<cstdio>#include<string.h>using names...原创 2018-03-28 18:59:40 · 300 阅读 · 1 评论 -
杭电acm1027全排列(回溯算法)
Problem DescriptionNow our hero finds the door to the BEelzebub feng5166. He opens the door and finds feng5166 is about to kill our pretty Princess. But now the BEelzebub has to beat our hero first. f...原创 2018-03-28 15:04:27 · 460 阅读 · 0 评论 -
(搜索应用)Oil Deposits( UVA - 572 )
Oil Deposits UVA - 572 #include <iostream>#include<stdio.h>#include<queue>#include<stdlib.h>#include<string.h>using namespace std;char a[100][100];int vis[100][100...原创 2018-04-15 19:12:14 · 138 阅读 · 0 评论 -
(搜索)Tempter of the Bone((HDU - 1010)
The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone ...原创 2018-04-02 19:27:09 · 192 阅读 · 0 评论 -
N皇后问题
N皇后问题 HDU - 2553 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。 你的任务是,对于给定的N,求出有多少种合法的放置方法。 Input共有若干行,每行一个正整数...原创 2018-03-30 21:00:36 · 186 阅读 · 0 评论 -
T95要减肥(动态规划)
链接:https://www.nowcoder.com/acm/contest/79/B来源:牛客网时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld题目描述 T95提速啦,然而她觉得自己还是太慢了! 于是T95决定减肥——然而T95还喜欢吃麦当劳 现在有n种赛道,n家麦当劳,第i条赛道的痛...原创 2018-03-24 14:40:29 · 256 阅读 · 0 评论 -
(搜索)POJ-1979 Red and Black
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can'...原创 2018-03-24 14:24:34 · 159 阅读 · 0 评论 -
桶排序
#include#include#include#includeusing namespace std;int main(){ int *p,q[10005]; int n; p=new int[10005]; memset(q,0,sizeof(q)); cout<<"输入序列长度:"<<endl; cin>>n; int i=原创 2017-11-22 20:28:49 · 167 阅读 · 0 评论 -
快速幂模板
#include #include using namespace std;int power2(int a, int b, int c){ int res = 1; a %= c; while (b) { if (b%2==1) res = (res * a) % c; a =原创 2017-10-13 15:32:17 · 171 阅读 · 0 评论 -
hdu 3549 Flow Problem
注意:起点与终点相同时的情况方法一.邻接矩阵#include <iostream>#include<queue>#include<stdio.h>#include<string.h>using namespace std;const int INT=1000000005;const int maxx=105;int map1[maxx]...原创 2018-06-03 10:16:26 · 177 阅读 · 0 评论