昨天模拟赛的时候坑了好久,刚开始感觉是dp,仔细一看数据范围太大。

题目大意:一个人要参加考试,一共有n个科目,每个科目都有一个相应的队列,完成这门科目的总时间为a+b*(前面已完成科目所花的总时间)。问:怎样安排考试的顺序使考完所花的总时间最短。

分析:假设已经花了time时间,在剩下的科目中任意取两个科目x,y。

先考试x:Tx=time+(ay*time+ax+bx*by*(ax+time));

先考试y:Ty=time+(by*time+bx+ax+ay*(bx+time))。

化简之后发现花费时间的差距在ax*by,ay*bx,那么按照ai/bi的大小进行排序就ok了。

 #include <stdio.h>
#include <string.h>
#include <stdlib.h> #define N 100010
#define INF 0xffffffff
#define MOD (365*24*60*60) struct node
{
__int64 a, b;
double s;
};
node stu[N]; int cmp (const void *a, const void *b)
{
node *c = (node *)a;
node *d = (node *)b; return c->s > d->s ? :-;
} int main ()
{
__int64 n, i, sum; while (scanf ("%I64d", &n), n)
{
for (i=; i<n; i++)
{
scanf ("%I64d %I64d", &stu[i].a, &stu[i].b);
if (!stu[i].a)
stu[i].s = ;
else if (!stu[i].b)
stu[i].s = INF;
else
stu[i].s = 1.0 * stu[i].a / stu[i].b;
} qsort (stu, n, sizeof(stu[]), cmp);
sum = ; for (i=; i<n; i++)
{
sum += (stu[i].a + stu[i].b * sum) % MOD;
sum %= MOD;
} printf ("%I64d\n", sum);
} return ;
}

hdu 4442 Physical Examination (2012年金华赛区现场赛A题)的更多相关文章

  1. hdu4445 CRAZY TANK 2012金华赛区现场赛D题

    简单推下物理公式  对角度枚举 物理公式不会推啊智商捉急啊.... 到现在没想通为什么用下面这个公式就可以包括角度大于90的情况啊... #include<iostream> #inclu ...

  2. HDU 5128 The E-pang Palace(2014广州赛区现场赛B题 计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5128 解题报告:在一个平面上给出n个点的坐标,用这n个点作为矩形的四个顶点,作两个矩形,要求两个矩形不 ...

  3. HDU 5120 A Curious Matt(2014北京赛区现场赛A题 简单模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5112 解题报告:扫一遍 #include<cstdio> #include<cstr ...

  4. HDU 4442 Physical Examination(贪心)

    HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...

  5. HDU 4442 Physical Examination

    Physical Examination Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  6. hdu 4442 Physical Examination 贪心排序

    Physical Examination Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...

  7. HDU 4442 Physical Examination(关于贪心排序)

    这个题目用贪心来做,关键是怎么贪心最小,那就是排序的问题了. 加入给定两个数a1, b1, a2, b2.那么如果先选1再选2的话,总的耗费就是a1 + a1 * b2 + a2; 如果先选2再选1, ...

  8. HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环 ...

  9. HDU 5073 Galaxy(2014鞍山赛区现场赛D题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5073 解题报告:在一条直线上有n颗星星,一开始这n颗星星绕着重心转,现在我们可以把其中的任意k颗星星移 ...

随机推荐

  1. 软件版本号(BETA、RC、ALPHA、Release、GA等)

    Alpha:        Alpha是内部测试版,一般不向外部发布,会有很多Bug.除非你也是测试人员,否则不建议使用.是希腊字母的第一位,表示最初级的版本,alpha 就是α,beta 就是β , ...

  2. openwrt 配置rsync服务

    一: rsyn简介 remote synchronize顾名思意就知道它是一款实现远程同步功能的软件,它在同步文件的同时,可以保持原来文件的权限.时间.软硬链接等附加信息. rsync是用 “rsyn ...

  3. 细数AutoLayout以来UIView和UIViewController新增的相关API

    本文转载至 http://www.itjhwd.com/autolayout-uiview-uiviewcontroller-api/ 细数AutoLayout以来UIView和UIViewContr ...

  4. SpringInAction4笔记——装配

    重点:常用的上下文环境 AnnotationConfigApplicationContext ClassPathXmlApplicationContext FileSystemXmlApplicati ...

  5. bash exec

    1 当exec执行命令时,会为该命令创建shell进程,并且终止老的shell进程的执行,并且保留老的shell进程的进程号 [root@localhost ~]# cat test_exec.sh ...

  6. FZU2150 Fire Game —— BFS

    题目链接:https://vjudge.net/problem/FZU-2150 Problem 2150 Fire Game Accept: 2702    Submit: 9240 Time Li ...

  7. 更改NavigationView侧滑菜单文字颜色

    NavigationView menu默认icon和title会随着菜单状态改变而改变,选择某个菜单后再次打开侧边菜单后会发现该菜单的icon和title会变成应用的主颜色,其他菜单项仍然为黑色. 如 ...

  8. hdu 4544 湫湫系列故事——消灭兔子(优先队列)

    题意:n只兔子(有血量),m只箭(有伤害.花费),每只兔子只能被射一次,求射死所有兔子的最少花费. 思路:贪心,2重循环,兔子从血量高到低,箭从伤害高到低,用能射死兔子的箭中花费最小的箭射. #inc ...

  9. fuse的mount机制 2 -系统调用mount

    经过上一篇的分析,目前已经知道mount函数最终进入到mount.c 中的 int fuse_kern_mount(const char *mountpoint, struct fuse_args * ...

  10. Balancing Act(树的重心)

    传送门 Balancing Act Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14070   Accepted: 593 ...