链接:

http://poj.org/problem?id=1456

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/G

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib> using namespace std; #define N 11000
#define INF 0xfffffff struct node
{
int a,b; }p[N]; int cmp(node a, node b)
{
return a.a > b.a;
}
int main()
{
int n,i,j,vis[N];
while(scanf("%d",&n)!=EOF)
{
memset(vis,0,sizeof(vis));
memset(p,0,sizeof(p)); for(i=0;i<n;i++)
scanf("%d %d",&p[i].a,&p[i].b); sort(p,p+n,cmp); int sum=0;
for(i=0;i<n;i++)
{
for(j=p[i].b;j>0;j--)
{
if(vis[j]==0)
{
sum=sum+p[i].a;
vis[j]=1;
break;
}
}
}
printf("%d\n",sum);
}
return 0;
}

(并查集 贪心思想)Supermarket -- POJ --1456的更多相关文章

  1. [POJ2054]Color a Tree (并查集+贪心)

    POJ终于修好啦 题意 和UVA1205是同一题,在洛谷上是紫题 有一棵树,需要给其所有节点染色,每个点染色所需的时间是一样的都是11.给每个点染色,还有一个开销“当前时间×ci×ci”,cici是每 ...

  2. HDU 1598 find the most comfortable road 并查集+贪心

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1598 find the most comfortable road Time Limit: 1000 ...

  3. POJ 1456 Supermarket 区间问题并查集||贪心

    F - Supermarket Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  4. poj 1456 Supermarket - 并查集 - 贪心

    题目传送门 传送点I 传送点II 题目大意 有$n$个商品可以销售.每个商品销售会获得一个利润,但也有一个时间限制.每个商品需要1天的时间销售,一天也只能销售一件商品.问最大获利. 考虑将出售每个物品 ...

  5. POJ1456:Supermarket(并查集+贪心)

    Supermarket Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17634   Accepted: 7920 题目链接 ...

  6. POJ_1456 Supermarket 【并查集/贪心】

    一.题面 POJ1456 二.分析 1.贪心策略:先保证从利润最大的开始判断,然后开一个标记时间是否能访问的数组,时间尽量从最大的时间开始选择,这样能够保证后面时间小的还能够卖. 2.并查集:并查集直 ...

  7. Supermarket POJ - 1456(贪心)

    题目大意:n个物品,每个物品有一定的保质期d和一定的利润p,一天只能出售一个物品,问最大利润是多少? 题解:这是一个贪心的题目,有两种做法. 1 首先排序,从大到小排,然后每个物品,按保质期从后往前找 ...

  8. Day5 - H - Supermarket POJ - 1456

    A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold ...

  9. 利用并查集+贪心解决 Hdu1232

    畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

随机推荐

  1. MVC 发布到IIS中的配置方法

    MVC 发布到IIS中的配置方法  http://msdn.microsoft.com/zh-cn/library/gg703322(v=vs.98).aspx

  2. 数据文件导入mysql时出现中文乱码问题

    http://www.ynpxrz.com/n773257c2024.aspx 从shell进入mysql, mysql> show variables like ‘%char%'; +---- ...

  3. Linux下php5.3.3安装mcrypt扩展

    具体操作: 一.下载软件包 1.下载php(版本要与系统安装的一致) http://pan.baidu.com/s/1mifTbfE 2.下载libmcrypt(安装mcrypt需要此软件包) htt ...

  4. LeanCloud

    [Nodejs 访问 LeanCloud] 代码中使用 SDK: var AV = require('avoscloud-sdk') AV.initialize('AppID', ''AppKey) ...

  5. test5

    ## 前言 因为vs2010没有集成mvvmlight 所以想要使用mvvmlight的relaycomman需要引用dll 需要测试某个功能的时候,不能进行快带的集成 ## 引用mvvmlight ...

  6. Spark之 Spark Streaming整合kafka(Java实现版本)

    pom依赖 <properties> <scala.version>2.11.8</scala.version> <hadoop.version>2.7 ...

  7. Python iter() 函数

    Python iter() 函数  Python 内置函数 描述 iter() 函数用来生成迭代器. 语法 以下是 iter() 方法的语法: iter(object[, sentinel]) 参数 ...

  8. Factorial Trailing Zeroes (Divide-and-Conquer)

    QUESTION Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should ...

  9. 【c++】c++中重载输出操作符,为什么要返回引用

    针对:ostream & operator <<(ostream & os, const ClassType &object) 说明几点: 1.第一个形参为对ost ...

  10. C#通过反射获得对象所有属性和值

    C#获得对象的所有属性和值 public void GetPros() { UserInfo userInfo = new UserInfo(); userInfo.ID = ; userInfo.N ...