码迷,mamicode.com
首页 > 其他好文 > 详细

贝壳找房函数最值

时间:2018-06-17 20:53:33      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:info   cout   std   turn   bool   space   return   image   bit   

技术分享图片

技术分享图片

题解:考虑两个函数 a * ( c * x + d ) + b = ac * x + ad + b,c * ( a * x + b ) + d = ac * x + cb + d,说明和x的系数没有关系,所以按照 ad + b < cb + d排序求解即可。

哎,第一次爆o,按照提示想了个排序,a小的优先,当a相等时b大的优先,结果一直wa。。。。wa,惨烈的教训告诉我下次排序要仔细推一波。

 1 #include<bits/stdc++.h>
 2 #define maxn (int)1e4 + 7
 3 using namespace std;
 4 
 5 struct node{
 6     int a, b;
 7     bool operator < (const node& i) const { return a * i.b + b < i.a * b + i.b; }
 8 } c[maxn];
 9 
10 int T, n, x;
11 
12 int main()
13 {
14     cin >> T;
15     while(T--){
16         cin >> n >> x;
17         for(int i = 1; i <= n; i++) cin >> c[i].a;
18         for(int i = 1; i <= n; i++) cin >> c[i].b;
19         sort(c + 1, c + n + 1);
20         
21         int res = x;
22         for(int i = 1; i <= n; i++){
23             res = (res * c[i].a + c[i].b) % 10;
24         }
25         cout << res << endl;
26     }
27     return 0;
28 }

 

贝壳找房函数最值

标签:info   cout   std   turn   bool   space   return   image   bit   

原文地址:https://www.cnblogs.com/zgglj-com/p/9193578.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!