Hdu 5170 5171

Source: Internet
Author: User
Tags mul

Hdu 5170 5171

Hdu 5170 meaning: given four integers a, B, c, d. Compare the sizes of a ^ B and c ^ d,
If the data size is small, you can simply do it. Now the data is relatively large and can be compared with the logarithm on both sides;
But pay attention to accuracy issues!

#include 
  
   #include 
   
    #include 
    
     #include 
     
      #include #include 
      
       using namespace std;int a,b,c,d;int main(){ while(cin>>a>>b>>c>>d) { double tmp1=b*log10(a*1.0); double tmp2=d*log10(c*1.0); if(tmp1-tmp2>1e-9) printf(">\n"); else if(tmp2-tmp1>1e-9) printf("<\n"); else printf("=\n"); } return 0;}
      
     
    
   
  

Hdu 5171: given a set, the number in it may be repeated. Now we can retrieve two numbers a and B each time, and then add a + B to the set, this operation can be repeated k times
The final set is expressed as A = {A1, A2, A3 ..... An };
Sum = A1 + A2 + A2 + A3 + ...... + The maximum value of;
Greedy processing, that is, the maximum and secondary values in the original set are obtained each time. The data can be directly simulated when the data is small. Now the data is a little big. recursive formula:
A1 and b1 are used to represent the maximum values in the original set, and the secondary values

Add a1 + b1 to the set in the first operation
Add 2a1 + b1 to the set in the second operation
The third operation 3a1 + 2b1 joins the set.
Add 5a1 + 3b1 to the set for the fourth time.
.
.
.
.
.
It is found to be a fib series, and the sum of the first k items can be obtained through matrix acceleration;

# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include const int MOD = 1e7 + 7; using namespace std; typedef long ll; int a [100100]; struct matrix {ll f [5] [5];}; matrix Co; // matrix mul (matrix a, matrix B) {matrix c; memset (c. f, 0, sizeof (c. f); for (int I = 0; I <4; I ++) for (int j = 0; j <4; j ++) for (int k = 0; k <4; k ++) {c. f [I] [j] + = (. f [I] [k] * B. f [k] [j]) % MOD; c. f [I] [j] % = MOD;} return c;} matrix quick_mod (matrix a, int B) {matrix s; memset (s. f, 0, sizeof (s. f); for (int I = 0; I <4; I ++) s. f [I] [I] = 1; while (B) {if (B & 1) s = mul (s, a); B> = 1; a = mul (a, a);} return s;} int main () {int n, k; Co. f [0] [0] = 1, Co. f [0] [1] = 1, Co. f [0] [2] = 0; Co. f [1] [0] = 1, Co. f [1] [1] = 0, Co. f [1] [2] = 0; Co. f [2] [0] = 1, Co. f [2] [1] = 1, Co. f [2] [2] = 1; while (cin> n> k) {ll ans = 0; int a1, b1; for (int I = 1; I <= n; I ++) {scanf ("% d", & a [I]); ans = (ans + a [I]) % MOD ;} sort (a + 1, a + 1 + n); a1 = a [n], b1 = a [n-1]; // maximum matrix tmp = Co; tmp = quick_mod (tmp, k); ll left = tmp. f [2] [0] * 1% MOD + tmp. f [2] [1] * 0% MOD + tmp. f [2] [2] * 0% MOD; ans = (ans + left * a1 % MOD) % MOD; tmp = Co; tmp = quick_mod (tmp, k-1 ); ll right = tmp. f [2] [0] * 1% MOD + tmp. f [2] [1] * 0% MOD + tmp. f [2] [2] * 0% MOD; ans = (ans + (right + 1) * b1 % MOD) % MOD; printf ("% I64d \ n ", ans);} return 0 ;}
     
    
   
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.