首页 > 编程语言 > 详细

ZOJ 1755 && POJ 1547 Clay Bully(简单排序+map容器)

时间:2015-01-27 20:21:32      阅读:320      评论:0      收藏:0      [点我收藏+]

链接: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容器)

原文:http://blog.csdn.net/u013050857/article/details/43198799

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!