链接:

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. substring_index 用法

    substring_index http://blog.csdn.net/wolinxuebin/article/details/7845917 1.substring_index(str,delim ...

  2. R及Rstuio下载及配置,及基本使用介绍

    1.R和Rstudio下载地址 https://cran.rstudio.com/a 2.Rstudio 的配置 外观.代码显示比例配置 选中tools 选中globle options 选中appe ...

  3. 【Python基础教程第2版】——第二讲:列表和元组

    引言: 什么是数据结构? 数据结果是通过某种方式(例如对元素进行编号)组织在一起的数据元素的集合.Python中最常用的数据结构是序列. Python包含6种内建的序列:列表和元组(最常用:列表可以修 ...

  4. UVa 230 Borrowers(map和set)

    I mean your borrowers of books - those mutilators of collections, spoilers of the symmetry of shelve ...

  5. Linux符号连接的层数过多

    转:http://blog.csdn.net/ta893115871/article/details/7458869 创建符号链接的时候一定要使用绝对路径,例如:/usr/local/cxxt/con ...

  6. php多进程中的阻塞与非阻塞

    我们通过pcntl_fork来创建子进程,使用pcntl_wait和pcntl_waitpid来回收子进程. 子进程退出后,父进程没有及时回收,就会产生僵尸进程.   例1: <?php def ...

  7. linux下memcache安装

    安装配置 1. 安装libevent # tar zxf libevent-1.4.6-stable.tar.gz # cd libevent-1.4.6-stable # ./configure # ...

  8. DB2事务日志

    1.DB2数据库的日志原理 事务日志记录数据库中所有对象和数据的改变,在早前版本中最大可达256G,其大小为( logprimary + logsecond ) * logfilsiz,其中logpr ...

  9. Java 的CardPanel用法

    Java code? 1 2 3 4 5 6               card = new CardLayout(5,5);//5,5是组件间隔                pane = new ...

  10. 怎样完整地离线更新并升级基于 Debian 的操作系统

    不久之前我已经向你展示了如何在任意离线的 Ubuntu 和 Arch Linux 操作系统上安装软件. 今天,我们将会看看如何完整地离线更新并升级基于 Debian 的操作系统. 和之前所述方法的不同 ...