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
{
char Name[];
int Age;
}Desd; char Father[MAX_N][];
char Child[MAX_N][];
int Age[MAX_N];
Desd Descen[MAX_N];
int Cmp( Desd a, Desd b ); int main()
{
int n, Count; Count = ;
strcpy( Descen[].Name, "Ted" );
Descen[].Age = ; scanf( "%d", &n );
for ( int i = ; i < n; ++i )
{
int Num, Index_Father, EndDescen; Index_Father = EndDescen = ;
Count++; scanf( "%d\n", &Num );
for ( int j = ; j < Num; ++j )
scanf( "%s %s %d", Father[j], Child[j], &Age[j] ); while ( Index_Father < Num )
{
for ( int m = ; m < Num; ++m )
{
if ( strcmp( Descen[Index_Father].Name, Father[m] ) == )
{
EndDescen++;
strcpy( Descen[EndDescen].Name, Child[m] );
Descen[EndDescen].Age = Descen[Index_Father].Age - Age[m];
}
}
Index_Father++;
} sort( Descen, Descen + Num + , Cmp ); printf( "DATASET %d\n", Count );
for ( int n = ; n <= Num; ++n )
printf( "%s %d\n", Descen[n].Name, Descen[n].Age );
} return ;
} int Cmp( Desd a, Desd b )
{
if ( a.Age == b.Age )
return strcmp( a.Name, b.Name ) < ;
else
return a.Age > b.Age;
}
poj 2021 Relative Relatives(暴力)的更多相关文章
- POJ 2021 Relative Relatives
Relative Relatives Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3339 Accepted: 146 ...
- POJ 2021 Relative Relatives(map+树的遍历)
题意: 今天是Ted的100岁生日.凑巧的是,他家族里面每个人都跟他同一天生日,但是年份不同. 现在只给出一些 父亲的名字,孩子的名字,以及孩子出生时父亲的年龄, 要求将Ted以外的家族成员按年龄降序 ...
- poj 3714 Raid【(暴力+剪枝) || (分治法+剪枝)】
题目: http://poj.org/problem?id=3714 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#prob ...
- POJ 3522 Slim Span 暴力枚举 + 并查集
http://poj.org/problem?id=3522 一开始做这个题的时候,以为复杂度最多是O(m)左右,然后一直不会.最后居然用了一个近似O(m^2)的62ms过了. 一开始想到排序,然后扫 ...
- poj 2585 Window Pains 暴力枚举排列
题意: 在4*4的格子中有9个窗体,窗体会覆盖它之下的窗体,问是否存在一个窗体放置的顺序使得最后的结果与输入同样. 分析: 在数据规模较小且不须要剪枝的情况下能够暴力(思路清晰代码简单),暴力一般分为 ...
- POJ 1012 Joseph 推导,暴力,约瑟夫环,打表 难度:2
http://poj.org/problem?id=1012 答案以954ms飘过,不过这道题可以轻松用打表过 思路:如果我们把每个人位于数组中的原始编号记为绝对编号,每次循环过后相对于绝对编号为0的 ...
- POJ - 3279(枚举+暴力)
Fliptile Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14297 Accepted: 5257 Descrip ...
- POJ 2896 另解暴力
就是简单的用strstr函数对字符串进行处理. 另解:暴力(就是用strstr函数对字符串进行处理)另解:暴力(普通的字符串处理 .关键是strstr函数): #include<stdio.h& ...
- POJ 2407:Relatives(欧拉函数模板)
Relatives AC代码 Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16186 Accept ...
随机推荐
- zoom和transform:scale()的区别
zoom和transform:scale()都可以用于缩放,目前移动端存在各种各样不同屏幕大小的手机,为了兼容不同宽度的屏幕,我们可以基于某一屏幕宽度大小(比如iPhone5的320,这个根据设计稿来 ...
- iOS工程上传AppStore时遇到的问题“ERROR ITMS-90046”解析
在我们将代码写完整,测试没有bug之后,我们就可以将它上传到AppStore了,上传的过程只要操作正确并不会有太大的问题,但是打包的过程中会出现一些小问题,导致打的包不能上传或者上传的时候会出现错误. ...
- UVa1585 Score
#include <stdio.h> int main(){ int T, O, score; char str[81], *p; scanf("%d" ...
- JavaSE_ 多线程 总目录(23~24)
JavaSE学习总结第23天_多线程123.01 多线程程序的引入23.02 进程概述及多进程的意义23.03 线程概述及多线程的意义23.04 并行和并发的区别23.05 Java程序运行原理和JV ...
- JQuery中判断checkbox是否选中与禁用鼠标右键
if ($("#wds_checkbox").attr("checked")) { flag = ; } else { flag = ; } 禁用鼠标右键 // ...
- C# DES加解密
加密 public static string Encrypt(string sourceString, string key, string iv) { try { byte[] btKey = E ...
- Githut Token (hidden): Githut 安装验证
登录https://github.com 进入https://github.com/settings/profile 参考 http://jingyan.baidu.com/article/22fe7 ...
- pwntools安装使用方法
pwntools是一个CTF框架和漏洞利用开发库,用Python开发,由rapid设计,旨在让使用者简单快速的编写exploit. pwntools对Ubuntu 12.04和14.04的支持最好,但 ...
- 操作 IoT 设备内嵌 SQLite
Win10 IoT C#开发 5 - 操作 IoT 设备内嵌 SQLite 数据库 CURD Windows 10 IoT Core 是微软针对物联网市场的一个重要产品,与以往的Windows版本 ...
- 关于LD_DEBUG (转载)
引用 LD_DEBUGThe dynamic library loader used in linux (part of glibc) has some neat tricks. One of the ...