zoukankan      html  css  js  c++  java
  • hdu 4310

    贪心,刚做此题时,就意识到了是贪心,但贪心思路一直没找对,wa了n次,在纠结中终于想出正确的思路


    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    using namespace std;
    struct node
    {
    	int x,y;
    };
    node f[25];
    bool cmp(node a,node b)
    {
    	return a.y*b.x<b.y*a.x;
    }
    int main()
    {
    	int n;
    	while(cin>>n)
    	{
    		int i;
    		long long amount=0,tot=0;
    		for(i=0;i<n;i++)
    		{
    			scanf("%d%d",&f[i].x,&f[i].y);
    			amount+=f[i].x;
    		}
    		sort(f,f+n,cmp);
    		for(i=0;i<n;i++)
    		{
    			tot+=amount*f[i].y;
    			amount-=f[i].x;
    		}
    		cout<<tot<<endl;
    	}
    	return 0;
    }


  • 相关阅读:
    centos7安装kde桌面
    centos7安装NVIDIA驱动
    15日报
    11日报
    14日报
    奖励加分
    课程建议
    13日报
    12日报
    每日总结1213
  • 原文地址:https://www.cnblogs.com/lj030/p/3002281.html
Copyright © 2011-2022 走看看