ACM
文章平均质量分 70
sun_apple_123
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
多项式相乘
//存储结构struct PolyNode{ int coef;//系数 int expon;//指数 PolyNode * next;//指针域}//多项式相乘PolyNode* Multiply(PolyNode* L1,PolyNode* L2){ PolyNode *t1,*t2,*t,*rear,*L; int c,e; L=(...原创 2019-08-05 22:07:47 · 696 阅读 · 0 评论 -
大整数相加
两个大整数用单链表H1和H2表示,链表中每个结点存储一位数字(假设大整数存储是由低位到高位逆序存储的)。大整数相加代码如下:LNode * Add(LNode* H1,LNode* H2){ LNode *p1=H1->next,*p2= H2->next,*p=NULL; LNode *H3=(LNode*)malloc(sizeof(LNode));//创...原创 2019-08-05 21:49:10 · 212 阅读 · 0 评论 -
POJ1007 DNA Sorting
排序#include #include#includeusing namespace std;bool comp(string a,string b);int main(){ int n,m; string str[105]; while(cin>>n>>m){ for(int i=0;i<m;i++) cin>>st原创 2016-05-29 19:33:57 · 226 阅读 · 0 评论 -
1008 数组元素循环右移问题
#includeusing namespace std;int main(){ int n,m,a[105]; while(cin>>n>>m){ int i,j,t; for(i=0;i<n;i++) cin>>a[i]; if(n/2>m){ for(i=0;i<n-m;i++原创 2016-05-10 19:03:28 · 301 阅读 · 0 评论 -
1013 数素数
题目:令Pi表示第i个素数。现任给两个正整数M 4,请输出PM到PN的所有素数。在第四个测试点跪了好几次,经过不断的调整发现我的这种算法的i必须在[104750,104780]范围内。#include#includeusing namespace std;int main(){ int m,n,p[10005]; cin>>m>>n; int i原创 2016-05-16 10:33:58 · 378 阅读 · 0 评论 -
POJ3414 Pots
大概思路:题意是解最少步骤及打印对应步骤。Min求解可以用BFS,但是此题还需记录步骤。 故用BFS+vector解决此题,第一次TLE,加了visited[105][105]判断后就AC了。#include#include#include#includeusing namespace std;struct Pot{ int A,B,steps; ve原创 2016-04-25 17:00:35 · 283 阅读 · 0 评论 -
Image Perimeters
Problem DescriptionTechnicians in a pathology lab analyze digitized images of slides. Objects on a slide are selected for analysis by a mouse click on the object. The perimeter of the boundary of原创 2016-07-05 17:55:08 · 465 阅读 · 0 评论 -
POJ1703 Find them, Catch them
题目链接:http://poj.org/problem?id=1703大概思路:题目要确认的有三种结果,所以不能直接找出a的不同集合再与b合并。由于事先并不知道a、b是哪一派别的,所以开一个2*maxn大的数组,分成两个派别:a属于a,a属于a+maxn。每次执行D操作其实就是合并(a,b+maxn)和(a+maxn,b),最后判断a,b是否同一派别,a,b+maxn是否同一派别即可。TL原创 2016-08-21 15:34:25 · 252 阅读 · 0 评论 -
POJ3253 Fence Repair
注意题目的数据大小,ans要用long long类型。#include #includeusing namespace std;int n,b[200005];void solve();int main(){ cin>>n; for(int i=0;i<n;i++){ cin>>b[i]; } sort(b,b+n); sol原创 2016-08-18 21:24:54 · 250 阅读 · 0 评论 -
POJ3069 Saruman's Army
(1)从最左侧s点开始找在s+R范围内的最右侧的e点,即为标记点;(2)再从e点出发找最靠近s+R范围的点,更新s点,回到(1);#include #includeusing namespace std;int r,n,p[1005];void solve();int main(){ while(cin>>r>>n&&r!=-1||n!=-1){ fo原创 2016-08-18 20:25:26 · 202 阅读 · 0 评论 -
POJ3617 Best Cow Line
首尾比较时,主要问题在于它们相等的处理。PE的话请仔细看清输出要求。#include using namespace std;int n;char s[2005],e[2005];void solve();int main(){ cin>>n; for(int i=0;i<n;i++){ cin>>s[i]; } solve(原创 2016-08-18 19:53:23 · 241 阅读 · 0 评论 -
1007 素数对猜想
#include#includeusing namespace std;int main(){ int n; while(cin>>n){ int i,j,t=0,m=0,num=0; for(i=2;i<=n;i++){ bool flag=0; for(j=2;j<=sqrt(i);j++){原创 2016-05-09 11:07:25 · 383 阅读 · 0 评论 -
1002 写出这个数 (20)
#include #includeusing namespace std;int main(){ char str[105]; int num[105],len; while(cin>>str){ int i,j; len=strlen(str); for(i=0;i<len;i++){原创 2016-04-26 19:50:02 · 382 阅读 · 0 评论 -
POJ3259 Wormholes
题目来源:http://poj.org/problem?id=3259第一个是Bellman-Ford 、第二个是Floyd-Warshall。(一)#include #include#includeusing namespace std;struct edge{ int from,to,cost;}ed[6005];int F,N,M,W;int d[5原创 2016-08-26 11:36:57 · 245 阅读 · 0 评论 -
POJ2139 Six Degrees of Cowvin Bacon
题目来源:http://poj.org/problem?id=2139题意:有N只牛,在同一部电影Mi里的Ni只牛它们之间的距离为1,当两只牛不在同一部电影里,有第三只牛分别在那两只牛拍的电影里,则它们的距离为2。要求的是以其中一只牛为起点与其他牛之间的距离之和最短。N#include #include#includeusing namespace std;const int原创 2016-08-24 11:12:19 · 379 阅读 · 0 评论 -
HDU1005 Number Sequence
( 1 一开始开全局数组,MLT;后来用栈pop一次push一次,可循环还得O(n),TLE;最后的最后,只好找规律。#include #includeusing namespace std;int main(){ int a,b,n,flag[7][7]; while(cin>>a>>b>>n){ if(!a&&!b&&!n) break;原创 2016-05-23 21:37:43 · 233 阅读 · 0 评论 -
HDU1009 FatMouse' Trade
简单的贪心,就是在排序上浪费了点时间,还是对二维数组排序的comp函数没辙,最后用了struct。#include #include#includeusing namespace std;struct Node{ int a,b;}node[1005];bool comp(Node a,Node b);int main(){ int n,m; while原创 2016-05-24 20:30:43 · 213 阅读 · 0 评论 -
HDU1012 u Calculate e
简直就要拜倒在这输出上了~#include #includeusing namespace std;int func(int j);int main(){ int i,j; double e; cout<<"n e\n- -----------\n"; for(i=0;i<10;i++){ e=0; for(j=原创 2016-05-24 21:04:36 · 264 阅读 · 0 评论 -
HDU1060 Leftmost Digit
题意:求解N^N(1)的最左边的数字。思路:遇到这么大的数,只能求救数学公式了,恰好可以运用取对数的方法实现果的简化。原创 2016-05-26 11:27:24 · 229 阅读 · 0 评论 -
Digital Roots
Digital RootsTime Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 11 Accepted Submission(s) : 4Font: Times New Roman | Verdana | Georgia原创 2016-05-27 15:00:17 · 241 阅读 · 0 评论 -
POJ3295 Tautology
大概题意:输入为含有p, q, r, s, t代表的 五个逻辑变量及K, A, N, C, E代表的五个基本逻辑连接词的字符串,输出即判断是否为永真式。思路:参照http://blog.youkuaiyun.com/jun_sky/article/details/7002084的思路,即五个变量共2^5种情况(00000-11111),再从字符串尾部开始压栈, 分成三种情况考虑1)逻辑变量原创 2016-05-21 16:01:40 · 308 阅读 · 0 评论 -
POJ3009 Curling 2.0
题目来源:http://poj.org/problem?id=3009咋一看,求最短路径问题,不假思索地用bfs,但各种MLE、TLE,最后不得不转换思维用dfs+剪枝。#include using namespace std;int n,m;int board[25][25];int sx,sy;int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};原创 2016-08-18 15:41:29 · 203 阅读 · 0 评论 -
POJ3669 Meteor Shower
DescriptionBessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her safety, she vows to find原创 2016-08-17 18:03:24 · 291 阅读 · 0 评论 -
POJ2718 Smallest Difference
DescriptionGiven a number of distinct decimal digits, you can form one integer by choosing a non-empty subset of these digits and writing them in some order. The remaining digits can be written do原创 2016-08-17 16:07:05 · 222 阅读 · 0 评论 -
三角形
组成三角形的充要条件:最长边长(1)直接枚举:O(n^3)#include #includeusing namespace std;int main(){ int n,a[105]; while(cin>>n){ for(int i=0;i<n;i++){ cin>>a[i]; } int a原创 2016-08-15 17:42:12 · 370 阅读 · 0 评论 -
Packets
DescriptionA factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These products are always delivered to customers in the square原创 2016-07-20 14:53:48 · 550 阅读 · 0 评论 -
Function Run Fun
DescriptionWe all love recursion! Don't we? Consider a three-parameter recursive function w(a, b, c): if a 1 if a > 20 or b > 20 or c > 20, then w(a, b, c) returns: w(20, 20, 20)原创 2016-07-20 14:48:34 · 286 阅读 · 0 评论 -
Tiling
DescriptionIn how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tiling of a 2x17 rectangle. InputInput is a sequence of lines, each line co原创 2016-07-20 14:45:18 · 425 阅读 · 0 评论 -
Tree Recovery
DescriptionLittle Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital letters in the nodes. This is an example of原创 2016-07-07 15:12:23 · 257 阅读 · 0 评论 -
The Triangle
Problem Description73 88 1 02 7 4 44 5 2 6 5(Figure 1)Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route原创 2016-07-05 18:00:09 · 233 阅读 · 0 评论 -
Factorial
Problem DescriptionThe most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone)原创 2016-07-05 17:42:16 · 505 阅读 · 0 评论 -
Common Subsequence
DescriptionA subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = another sequence Z = is a subsequence of X if there exists原创 2016-07-12 13:30:07 · 212 阅读 · 0 评论 -
POJ1852 Ants
DescriptionAn army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking ant reaches an end of the pole, it immediatelly falls off it. When two ant原创 2016-08-16 08:20:30 · 241 阅读 · 0 评论 -
抽签问题
题目:每次从n个数里抽取一个数记录后并放回,问是否存在抽取的四个数之和为m的情况。当n下面的算法时间复杂度为O(n^2 log n)。#include #includeusing namespace std;int n,m;int a[1005],b[1000005];bool b_search(int x);void solve();int main(){原创 2016-08-16 11:44:04 · 911 阅读 · 0 评论 -
POJ3187 Backward Digit Sums
DescriptionFJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum adjacent numbers to produce a new list with one fewer原创 2016-08-17 11:30:09 · 246 阅读 · 0 评论 -
POJ3050 Hopscotch
DescriptionThe cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cows create a 5x5 rectilinear grid of digits paral原创 2016-08-17 10:59:40 · 253 阅读 · 0 评论 -
POJ1979 Red and Black
DescriptionThere 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 til原创 2016-08-16 19:53:02 · 250 阅读 · 0 评论 -
迷宫的最短路径
题目:给定一个大小为N*M的迷宫。迷宫由通道和墙壁组成,每一步可以向邻接的上下左右四格的通道移动。请求出从起点到终点所需的最小步数。#include #includeusing namespace std;const int INF=100000;int n,m,sx,sy,ex,ey;int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};int step原创 2016-08-16 16:54:03 · 716 阅读 · 0 评论 -
POJ2386 Lake Counting
DescriptionDue to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains原创 2016-08-16 16:06:08 · 204 阅读 · 0 评论 -
uva101 The Blocks Problem
模拟,vector#include #include#includeusing namespace std;int n;vector v[30];void find_block(int a,int& p,int& h);void back_odd(int p,int h);void add_onto(int p1,int h,int p2);int main(){原创 2016-07-21 16:47:44 · 248 阅读 · 0 评论
分享