
acm
zsyr
人生在世,努力二字。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
ACM 数论
//数论//辗转相除法int gcd(int a, int b){ if(b == 0) return a; return gcd(b,a%b);}//扩展欧几里得int extgcd(int a, int b, int &x, int &y){ if(b == 0){ x = 1; y = 0; return a; }else原创 2017-07-10 19:55:53 · 281 阅读 · 0 评论 -
HK Missing Numbers
#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#include<queue>#include<set>#include<iterator>#include<map>using namespace std;int main(){ int n;原创 2017-07-16 10:11:19 · 233 阅读 · 0 评论 -
HK Gridland Metro
#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#include<queue>#include<set>#include<iterator>#include<map>using namespace std;typedef long long ll;ty原创 2017-07-17 10:37:27 · 273 阅读 · 0 评论 -
HK Maximum Subarray Sum
#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#include<queue>#include<set>#include<iterator>#include<map>using namespace std;typedef unsigned long lo原创 2017-07-17 15:03:50 · 197 阅读 · 0 评论 -
DFS小练习
#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#include<queue>#include<set>#include<iterator>#include<map>using namespace std;typedef unsigned long lo原创 2017-07-18 09:45:50 · 215 阅读 · 0 评论 -
HDU1873 看病要排队(优先队列)
看病要排队看病要排队这个是地球人都知道的常识。 不过经过细心的0068的观察,他发现了医院里排队还是有讲究的。0068所去的医院有三个医生(汗,这么少)同时看病。而看病的人病情有轻重,所以不能根据简单的先来先服务的原则。所以医院对每种病情规定了10种不同的优先级。级别为10的优先权最高,级别为1的优先权最低。医生在看病时,则会在他的队伍里面选择一个优先权最高的人进行诊治。如果遇到两个优先权一样的病原创 2017-07-21 13:24:22 · 267 阅读 · 0 评论 -
HDU1434 幸福列车(优先队列)
Problem Description 一批幸福的列车即将从杭州驶向幸福的终点站——温州,身为总列车长的linle有一些奇怪的癖好。他会记录下全部乘客的名字(name)和他们的人品值(RP),根据这些将他们排序,并不时地从某辆列车里踢出人品最不好(RP值最低)的一个人,当两个人人品一样不好时,他就会踢出名字难听的人(linle认为按字典顺序,排在越在后面的人名字越难听)。当然出于列车行驶需要,他还原创 2017-07-21 14:07:40 · 234 阅读 · 0 评论 -
HDU1180 诡异的楼梯(BFS)
Problem Description Hogwarts正式开学以后,Harry发现在Hogwarts里,某些楼梯并不是静止不动的,相反,他们每隔一分钟就变动一次方向. 比如下面的例子里,一开始楼梯在竖直方向,一分钟以后它移动到了水平方向,再过一分钟它又回到了竖直方向.Harry发现对他来说很难找到能使得他最快到达目的地的路线,这时Ron(Harry最好的朋友)告诉Harry正好有一个魔法道原创 2017-07-21 18:27:33 · 213 阅读 · 0 评论 -
HDU4006 The kth great number(优先队列)
Problem Description Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number w原创 2017-07-21 23:00:59 · 239 阅读 · 0 评论 -
HDU1678 Shopaholic
ShopaholicProblem Description Lindsay is a shopaholic. Whenever there is a discount of the kind where you can buy three items and only pay for two, she goes completely mad and feels a need to buy all原创 2017-07-21 23:18:08 · 228 阅读 · 0 评论 -
HDU3152 Obstacle Course(BFS)
Problem Description You are working on the team assisting with programming for the Mars rover. To conserve energy, the rover needs to find optimal paths across the rugged terrain to get from its start原创 2017-07-21 23:48:53 · 265 阅读 · 0 评论 -
HDU1026 Ignatius and the Princess I(BFS)
Problem Description The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into feng5166’s castle. The castle is a large labyrinth.原创 2017-07-22 13:32:10 · 273 阅读 · 0 评论 -
HDU 1166 敌兵布阵
线段树基础题,数组要开大Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些原创 2017-07-19 10:35:26 · 160 阅读 · 0 评论 -
HDU 1556 color the ball
Color the ball Time Limit : 9000/3000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 0 Accepted Submission(s) : 0 Font: Times New Roman | Verdana | Georgia Font S原创 2017-07-19 10:55:19 · 165 阅读 · 0 评论 -
binarySearchTree 简单链表实现
//binarySearchTreestruct node{ int val; node *lson, *rson;}node* insert(node *p, int x){ if(p == null){ node *q = new node; q->val = x; q->lson = q->rson = null;原创 2017-07-22 19:08:32 · 241 阅读 · 0 评论 -
并查集简单实现
const int maxn = 50010;int root[maxn];//父亲int rank[maxn];//数的高度int n;//初始化n个元素void init(){ for(int i = 0; i < n; i++){ root[i] = i; rank[i] = 0; }}//查询树的根int find(int x){原创 2017-07-22 23:31:22 · 178 阅读 · 0 评论 -
HDU 1689 Just a HooK(线段树+延迟标记)
Just a Hook Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 0 Accepted Submission(s) : 0 Font: Times New Roman | Verdana | Georgia Font Size原创 2017-07-19 18:40:06 · 253 阅读 · 0 评论 -
hackerrank The Time in Words
#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#include<queue>#include<set>#include<iterator>#include<map>using namespace std;int main(){ string t原创 2017-07-14 09:57:04 · 256 阅读 · 0 评论 -
ACM 优先队列和堆
//heapint sz = 0;int heap[maxn];void push(int x){ int i = sz++; int p; while(i > 0){ p = (i - 1) / 2;//父亲节点编号 if(heap[p] <= x) break;//如果已经没有大小颠倒则退出 heap[i] = heap原创 2017-07-13 23:21:43 · 315 阅读 · 0 评论 -
ACM 组合数学
//C(n,r)int c(int n,int r){ int c=1; for(int i=0;i<r;i++) c=c*(n-i)/(i+1); return c;}//排列生成函数 next_permutation string str; cin >> str; sort(str.begin(), str.end()); cout <原创 2017-07-11 17:22:05 · 395 阅读 · 0 评论 -
ACM 线段树
求给定区间中的最值问题。对于长度为n的数列A,求数组A中下标在[i,j]里的最小值。 注: 这里下标从1开始 输入: 第一行两个整数n和q,分别表示数列的长度和询问的次数。 接下来n行为n个整数,表示数列A中的元素。 接下来q行中,每行有两个整数,表示所询问的区间[I, j]的两个端点 输出: 对每一个询问,给出指定区间中的最小值 样例输入: 9 2 5 8 1 3 6 4 9原创 2017-07-12 09:41:07 · 400 阅读 · 0 评论 -
hdu5256: 序列变换
题意:一个数列,a1,a2,a3,a4,—,an,需要最少修改多少个元素,使得这个序列严格递增?a[i]-i 非递减序列 因为a[i]#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#include<queue>using namespace std;int b原创 2017-05-22 19:28:34 · 310 阅读 · 0 评论 -
BFS------迷宫
走迷宫Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Submission(s) : 92 Accepted Submission(s) : 10 Font: Times New Roman | Verdana | Georgia Font Size: ← → P原创 2017-05-22 17:48:56 · 212 阅读 · 0 评论 -
最长有序上升子序列
如题,代码如下:#include<iostream>#include<algorithm>#include<stdio.h>using namespace std;const int n =10;int a[] = {1,2,3,5,4,7,9,6,10,8};int dp[n]; //dp[i]表示长度为i+1的上升子串中末尾元素的最小值int len[n];//len[i]表示以a[i]结尾的原创 2017-01-20 17:01:29 · 318 阅读 · 0 评论 -
hdoj 计算直线交点个数
计算直线的交点数Problem Description 平面上有n条直线,且无三线共点,问这些直线能有多少种不同交点数。 比如,如果n=2,则可能的交点数量为0(平行)或者1(不平行)。Input 输入数据包含多个测试实例,每个测试实例占一行,每行包含一个正整数n(n<=20),n表示直线的数量.Output 每个测试实例对应一行输出,从小到大列出所有相交方案,其中每个数为可能的交点数,每行原创 2017-01-18 14:16:11 · 447 阅读 · 0 评论 -
Sherlock and Cost
Array A contains the elements, A1,A2…AN. And array B contains the elements, B1,B2…BN. There is a relationship between Ai and Bi, ∀ 1 ≤ i ≤ N, i.e., any element Ai lies between 1 and Bi.Let the cost S原创 2017-01-15 19:25:19 · 394 阅读 · 0 评论 -
HDOJ1627 Krypton Factor
Krypton FactorTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Problem Description You have been employed by the organisers of a Super Krypton Factor Contest in which原创 2016-12-10 16:39:25 · 313 阅读 · 0 评论 -
HDOJ2553 N皇后问题
在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。 你的任务是,对于给定的N,求出有多少种合法的放置方法。Input 共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。Output 共有若干行,每行一个正整数,表示对应输入行的皇后的不同放置数量。Sample Input 1 8原创 2016-12-10 11:25:00 · 259 阅读 · 0 评论 -
Team Queue
Team QueueDescriptionQueues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, though it occurs often in everyday life.原创 2016-12-03 19:59:47 · 313 阅读 · 0 评论 -
the SetStack computer
The SetStack ComputerBackground from Wikipedia: “Set theory is a branch of mathematics created principally by the German mathematician Georg Cantor at the end of the 19th century. Initially controversi原创 2016-12-03 18:29:24 · 295 阅读 · 0 评论 -
Ananagrams Uva156
题意: 输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词,在判断是否满足条件时,字母不分大小写,但在输出时应保留输入的大小写,按字典序进行排列。代码如下:#include<iostream>#include<algorithm>#include<vector>#include<map>using namespace std;st原创 2016-12-03 15:31:42 · 303 阅读 · 0 评论 -
Andy's First Dictionary
输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大排列输出,单词不区分大小写。没有什么技巧,熟悉一下set和stringstream用法。#include<iostream>#include<sstream>#include<set>using namespace std;set<string> dict;int main(){ string s,buff; w原创 2016-12-03 14:55:34 · 306 阅读 · 0 评论 -
The Blocks Problem
Description Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics (STRIPS) used a block world原创 2016-12-03 12:39:30 · 279 阅读 · 0 评论 -
hackerrank Organizing Containers of Balls
#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#include<queue>#include<set>#include<iterator>#include<map>using namespace std;int M[110][110];long lon原创 2017-07-13 19:05:25 · 293 阅读 · 0 评论 -
hackerrank Queen's Attack II
#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#include<queue>#include<set>#include<iterator>#include<map>using namespace std;int main(){ int n, k原创 2017-07-13 13:37:45 · 336 阅读 · 0 评论 -
图论小结
BellmanFord\dijkstra\堆优化\FloydWarshall\prime\kruskal算法的简单实现//图的表示const int maxv = 1e5;//struct Edge{ int to, cost; };//vector<Edge> G[maxv];vector<int> G[maxv];int main(){ int v, e; scanf原创 2017-07-26 00:21:06 · 257 阅读 · 0 评论