poj 2021 Relative Relatives(暴力)】的更多相关文章

题目链接:http://poj.org/problem?id=2021 思路分析:由于数据较小,采用O(N^2)的暴力算法,算出所有后代的年龄,再排序输出. 代码分析: #include <iostream> #include <string.h> #include <algorithm> using namespace std; #define MAX_N ( 100 + 10 ) typedef struct Descendant { ]; int Age; }De…
Relative Relatives Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3339   Accepted: 1462 Description Today is Ted's 100th birthday. A few weeks ago, you were selected by the family to contact all of Ted's descendants and organize a surpr…
题意: 今天是Ted的100岁生日.凑巧的是,他家族里面每个人都跟他同一天生日,但是年份不同. 现在只给出一些 父亲的名字,孩子的名字,以及孩子出生时父亲的年龄, 要求将Ted以外的家族成员按年龄降序排序,如果年龄相同,则按字母排序. 思路:遍历树. 根据题意,可通过父子关系建立一个有权无向树,Ted作为树的根节点.通过从Ted所在节点开始遍历树,给每个节点赋值. 最后根据每个成员的年龄排序即可. 这里用到map,建立名字到编号的映射,从而获取一个人在树中的节点编号. #include <ios…
题目:  http://poj.org/problem?id=3714 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#problem/D Raid Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7355   Accepted: 2185 Description After successive failures in the battles aga…
http://poj.org/problem?id=3522 一开始做这个题的时候,以为复杂度最多是O(m)左右,然后一直不会.最后居然用了一个近似O(m^2)的62ms过了. 一开始想到排序,然后扫一个长度n - 1区间,要快速判定这个区间能否构成MST,一直都想不到优秀的算法,然后干脆暴力了. 两种方法,1.dfs,删边容易,标记一下就好,但是这是不行的,删边确实容易,但是dfs的时候多次访问无用的边,所以TLE了. 2.并查集,这个复杂度是O(n)的,能AC,但是我的思路还是有一点bug,…
题意: 在4*4的格子中有9个窗体,窗体会覆盖它之下的窗体,问是否存在一个窗体放置的顺序使得最后的结果与输入同样. 分析: 在数据规模较小且不须要剪枝的情况下能够暴力(思路清晰代码简单),暴力一般分为枚举子集(for(s=0;s<1<<n;++s))和枚举排列(next_permutation). 代码: //poj 2585 //sep9 #include <iostream> #include <algorithm> using namespace std;…
http://poj.org/problem?id=1012 答案以954ms飘过,不过这道题可以轻松用打表过 思路:如果我们把每个人位于数组中的原始编号记为绝对编号,每次循环过后相对于绝对编号为0的人的编号为相对编号,那么在这道题里,绝对编号是不重要的,只需要每次相对编号n都落在n>=k的位置上,那么n轮后自然所有的bad boy都被处理了. 而相对编号的推导: 设 id[i]为第i轮点到的编号(i从1开始计数),第i+1轮开始时存在的人数就会是2*k-i,点到的人的编号就是(id[i]+m-…
Fliptile Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14297   Accepted: 5257 Description Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in whic…
就是简单的用strstr函数对字符串进行处理. 另解:暴力(就是用strstr函数对字符串进行处理)另解:暴力(普通的字符串处理 .关键是strstr函数): #include<stdio.h> #include<string.h> struct Bing { char name[210]; int num; }bing[510]; struct Web { char name[10010]; int num; bool ok; int a[4]; }web[1010]; int…
Relatives AC代码 Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16186   Accepted: 8208 Description Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relativel…