ZOJ 1755 && POJ 1547 Clay Bully(简单排序+map容器)
来源:互联网 发布:人大经济论坛数据分析 编辑:程序博客网 时间:2024/05/09 02:32
链接: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; }}
0 0
- ZOJ 1755 && POJ 1547 Clay Bully(简单排序+map容器)
- ZOJ 1755 Clay Bully
- zoj 1755 Clay Bully
- ZOJ 1755 Clay Bully
- zoj 1755 Clay Bully
- POJ 1547 Clay Bully
- POJ 1547:Clay Bully
- POJ 1547 Clay Bully G++
- zoj 1755 Clay Bully(水~)
- ZOJ Problem Set - 1755 Clay Bully
- Clay Bully-1547
- POJ 1547 Clay Bully 结构体数组使用题意理解
- pku_1547 Clay Bully
- 北大ACM poj1547 Clay Bully
- zoj 3365 (map容器)
- poj 2503 map容器
- map容器简单应用
- 1755_Clay Bully
- poj2473 并查集删除点
- eventlet.Timeout遇到requests肿么失效了?
- UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现
- Unity3D事件派发机制之Delegate
- context-param与init-param的区别与作用
- ZOJ 1755 && POJ 1547 Clay Bully(简单排序+map容器)
- C#调用C++ dll,并向调用的函数传递“函数指针”
- 洛谷1594 护卫队 (st算法)
- qt与win7数据库连接
- POJ 2349&&ZOJ 1914 Arctic Network(kuangbin带你飞 专题六:最小生成树)
- 红黑树
- Nmap从探测到漏洞利用备忘录
- php 设计模式
- [每天一个知识点]16-软件工程-什么叫完成