HDU 4442 Physical Examination

水题。。。但是研究了半天

最后发现是这样排序的,两个项目进行排序,哪一个代价小,哪一个放前面

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

const int maxn=100000+10;
struct X
{
    long long a;
    long long b;
} s[maxn];
int n;

long long mod=31536000;

bool cmp(const X&a,const X&b)
{
    return (a.a+a.a*b.b+b.a)<(b.a+b.a*a.b+a.a);
}

int main()
{
    while(~scanf("%d",&n))
    {
        if(!n) break;
        for(int i=1; i<=n; i++)
            scanf("%lld %lld",&s[i].a,&s[i].b);
        long long sum=0;
        sort(s+1,s+1+n,cmp);
        for(int i=1; i<=n; i++)
        {
            long long ai=s[i].a;
            long long bi=s[i].b;
            sum=(sum+((sum*bi)%mod+ai)%mod)%mod;
        }
        printf("%lld\n",sum);
    }
    return 0;
}
时间: 2024-11-13 16:33:52

HDU 4442 Physical Examination的相关文章

HDU 4442 Physical Examination (贪心+排序)

Physical Examination Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5985    Accepted Submission(s): 1682 Problem Description WANGPENG is a freshman. He is requested to have a physical examinati

hdu 4442 Physical Examination (排序)

Physical Examination Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5813    Accepted Submission(s): 1625 Problem Description WANGPENG is a freshman. He is requested to have a physical examinat

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

这个题目用贪心来做,关键是怎么贪心最小,那就是排序的问题了. 加入给定两个数a1, b1, a2, b2.那么如果先选1再选2的话,总的耗费就是a1 + a1 * b2 + a2; 如果先选2再选1,总的耗费就是a2 + a2 * b1 + a1.这时比较两个数的大小,发现两边都有a1+a2,所以只是比较a1*b2和a2 * b1的大小. #include <cstdio> #include <cstring> #include <algorithm> using na

hdu 4442 贪心

http://acm.hdu.edu.cn/showproblem.php?pid=4442 Problem Description WANGPENG is a freshman. He is requested to have a physical examination when entering the university. Now WANGPENG arrives at the hospital. Er-.. There are so many students, and the nu

hdu4442 Physical Examination(贪心)

这种样式的最优解问题一看就是贪心.如果一下不好看,那么可以按照由特殊到一般的思维方式,先看n==2时怎么选顺序(这种由特殊到一般的思维方式是思考很多问题的入口): 有两个队时,若先选第一个,则ans=a1+a2+b2*a1;若先选第二个,则ans=a2+a1+b1*a2;所以选择顺序就比b2*a1和b1*a2就好了. 那么当有n>2个队时,能不能也这么搞?当然可以,每次剩下那几个队没选,我就两两比,两两之间比较时,之前用的时间都要加上是和顺序无关的,顺序影响的只是b2*a1和b1*a2而已(如果

hdu 4442 37届金华赛区 A题

题意:给出一些队伍,每个队伍有初始等待时间和每秒增加的时间,求最短时间 假设有两个队初始时间和每秒增加时间为a1,b1和a2,b2 若第选择第一个的时间小于第二个,则 a1+a2+a1*b2<a2+a1+a2*b1 化简得a1*b2<a2*b1,注意不要除过去,否则会有除以零报错 卧槽,MOD写错了,wa了半天 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include&l

HDU-4442-Physical Examination (2012年金华赛区现场赛A题)

Physical Examination Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5915    Accepted Submission(s): 1656 Problem Description WANGPENG is a freshman. He is requested to have a physical examinat

肺炎-维基百科

http://en.wikipedia.org/wiki/Pneumonia the number of words: 3110word           count---------------------pneumoniae        18respiratory       17streptococcus      15aspiration        11pulmonary          9interstitial       9sputum             6infl

高血压_翻译

网页: From Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/Hypertension 单词 word           count---------------------hypertension   [ha?p?'ten?(?)n]高血压  134 Hypertension is a medical condition in which a person has very high blood pressure