HDU-6446 Tree and Permutation
Posted asurudo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU-6446 Tree and Permutation相关的知识,希望对你有一定的参考价值。
1 #include <iostream> 2 #include <stdlib.h> 3 #include <string> 4 #include <vector> 5 #include <algorithm> 6 7 using namespace std; 8 int main() 9 { 10 int T; 11 scanf("%d",&T); 12 while(T--) 13 { 14 long long int n,a; 15 scanf("%lld %lld",&n,&a); 16 if(n==0||n>2) 17 { 18 printf("-1 -1 "); 19 } 20 else if(n==1) 21 { 22 printf("%lld %lld ",1,a+1); 23 } 24 else if((a&0x1)==1) 25 { 26 long long int b,c; 27 long long tmp = (a-1)/2; 28 b = 2*tmp*(tmp+1); 29 c = 2*tmp*(tmp+1)+1; 30 printf("%lld %lld ",b,c); 31 } 32 else 33 { 34 long long int b,c; 35 long long tmp = a/2-1; 36 b = tmp*tmp+2*tmp; 37 c = tmp*tmp+2*tmp+2; 38 printf("%lld %lld ",b,c); 39 } 40 } 41 return 0; 42 }
以上是关于HDU-6446 Tree and Permutation的主要内容,如果未能解决你的问题,请参考以下文章
(1009) HDU 6446 Tree and Permutation(规律+树上各个点的距离和)