ZOJ 1755 && POJ 1547 Clay Bully (simple sort +map container)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.