Links: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1755
Test instructions: Ms. Terry is a pre-school art teacher who likes to has her students work with clay. One of her assignments are to form a lump of clay in a block and then measure the dimensions of the block. However, in every class, there are always one child who insists on taking some clay from some and other child. Since Ms Terry always gives every child in a class the same amount of clay to begin with, can write a program that he LPs Ms Terry Find the bully and victim after she measures each child ' s finished block.
Idea: Sort, to find the smallest and largest names of people.
Code:
#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];d ouble 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;} }
Map of STL:
#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 (simple sort +map container)