首页 > 代码库 > ZOJ 1755 && POJ 1547 Clay Bully(简单排序+map容器)
ZOJ 1755 && POJ 1547 Clay Bully(简单排序+map容器)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1755
题意:Ms. Terry is a pre-school art teacher who likes to have her students work with clay. One of her assignments is to form a lump of clay into a block and then measure the dimensions of the block. However, in every class, there is always one child who insists on taking some clay from some other child. Since Ms. Terry always gives every child in a class the same amount of clay to begin with, you can write a program that helps Ms. Terry find the bully and victim after she measures each child‘s finished block.
思路:排序,求最小和最大的人的名字。
代码:
#include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <algorithm> using namespace std; const int Inf=0x3f3f3f3f; const int maxn=1000; const double eps=1e-6; const double pi=acos(-1.0); int n,m,i,j; int cost[maxn][maxn]; double s(double x,double y) { return ((x*x+y*y)*pi)/2.0; } struct node { int a,b,c; string str; } aa[250]; bool cmp(node zz, node cc) { return zz.a*zz.b*zz.c<=cc.a*cc.b*cc.c; } int bb[maxn]; int main() { int ncase,i,j,t,n,m; while(cin>>ncase&&ncase!=-1) { for(i=0;i<ncase;i++) { cin>>aa[i].a>>aa[i].b>>aa[i].c>>aa[i].str; //bb[i]=aa[i].a*aa[i].b*aa[i].c; } sort(aa,aa+ncase,cmp); cout<<aa[ncase-1].str<<" "<<"took clay from"<<" "<<aa[0].str<<"."<<endl; } }
STL 的MAP :
#include <stdio.h> #include <string.h> #include <iostream> #include <map> #include <algorithm> using namespace std; int main() { map<int ,string > qq; int i,j,n,m,a,b,c; string name; while(1) { cin>>n; if(n==-1) break; qq.clear(); for(i=0; i<n; i++) { cin>>a>>b>>c>>name; qq.insert(map<int ,string>::value_type(a*b*c,name)); } cout<<qq.rbegin()->second+" took clay from "+qq.begin()->second+"."<<endl; } }
ZOJ 1755 && POJ 1547 Clay Bully(简单排序+map容器)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。