zoukankan      html  css  js  c++  java
  • P2085 最小函数值

    题目描述

    有n个函数,分别为F1,F2,...,Fn。定义Fi(x)=Ai*x^2+Bi*x+Ci (x∈N*)。

    给定这些Ai、Bi和Ci,请求出所有函数的所有函数值中最小的m个(如有重复的要输出多个)。

    输入输出格式

    输入格式:

     

    输入数据:第一行输入两个正整数n和m。以下n行每行三个正整数,其中第i行的三个数分别位Ai、Bi和Ci。Ai<=10,Bi<=100,Ci<=10 000。

     

    输出格式:

     

    输出数据:输出将这n个函数所有可以生成的函数值排序后的前m个元素。这m个数应该输出到一行,用空格隔开。

    输入输出样例

    输入样例#1: 复制
    3 10
    4 5 3
    3 4 5
    1 7 1
    
    输出样例#1: 复制
    9 12 12 19 25 29 31 44 45 54

    说明

    数据规模:n,m<=10000

    刚开始的代码是这样的:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<queue>
     7 using namespace std;
     8 
     9 priority_queue<int,vector<int>,greater<int> > q;
    10 int n,m,f;
    11 int a,b,c;
    12 
    13 int main() 
    14 {
    15     scanf("%d%d",&n,&m);
    16     for(int i=1;i<=n;++i)
    17     {
    18         scanf("%d%d%d",&a,&b,&c);    
    19         for(int j=1;j<=m;++j)
    20         {
    21             f=a*j*j+b*j+c;
    22             q.push(f);        
    23         }
    24     }
    25     for(int i=1;i<=m;++i)
    26     {
    27         printf("%d ",q.top());
    28         q.pop();
    29     }    
    30     return 0;    
    31 }

    就是用小根堆做,挺明显的,,

    代码应该能理解,

    但是t了好多点,

    突然发现,,

    把第一个m循环改成到100

    就好了!!!

    再往后更大肯定选不上了,,

    所以,,强制减小循环次数,,

    还是数据太水了。。。

    所以,代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<queue>
     7 using namespace std;
     8 
     9 priority_queue<int,vector<int>,greater<int> > q;
    10 int n,m,f;
    11 int a,b,c;
    12 
    13 int main() 
    14 {
    15     scanf("%d%d",&n,&m);
    16     for(int i=1;i<=n;++i)
    17     {
    18         scanf("%d%d%d",&a,&b,&c);    
    19         for(int j=1;j<=100;++j)
    20         {
    21             f=a*j*j+b*j+c;
    22             q.push(f);        
    23         }
    24     }
    25     for(int i=1;i<=m;++i)
    26     {
    27         printf("%d ",q.top());
    28         q.pop();
    29     }    
    30     return 0;    
    31 }

    如果你不开心,那我就把右边这个帅傻子分享给你吧, 

    你看,他这么好看,那么深情的望着你,你还伤心吗? 

    真的!这照片盯上他五秒钟就想笑了。 

    一切都会过去的。

  • 相关阅读:
    一个简单的knockout.js 和easyui的绑定
    knockoutjs + easyui.treegrid 可编辑的自定义绑定插件
    Knockout自定义绑定my97datepicker
    去除小数后多余的0
    Windows Azure Web Site (15) 取消Azure Web Site默认的IIS ARR
    Azure ARM (1) UI初探
    Azure Redis Cache (3) 创建和使用P级别的Redis Cache
    Windows Azure HandBook (7) 基于Azure Web App的企业官网改造
    Windows Azure Storage (23) 计算Azure VHD实际使用容量
    Windows Azure Virtual Network (11) 创建VNet-to-VNet的连接
  • 原文地址:https://www.cnblogs.com/Mary-Sue/p/9440604.html
Copyright © 2011-2022 走看看