51nodcontest#24 A(xjb)

題目鏈接:http://www.51nod.com/contest/problem.html#!problemId=1804

 

題意:中文題誒~

 

思路: 三角形個數爲n-1, a, b數組元素個數也爲n-1, 爲了後面敘述方便先令n=n-1;

a數組元素用了一次,b數組元素用了兩次,所以sum=3*(n+1)*n/2, 要將其分配到 n 個三角形中, 即sum%n==0, 顯然只有n爲奇數時可行;

令 n=2*k+1, 則每個三角形的變權和爲 ans=sum/n=3*k+3;

接下來只要構造一個兩個數組使其滿足條件 ai + bi + bi+1 = ans 即可;

通過找規律可發現滿足條件的解爲 ai=i, bi=(i*k+1)mod n ? (i*k+1)mod n : n;

證明:

  1   2   3   4  ......  2*k+1

  k+1  2*k+1      k       2*k     ......      1

通過例表可以證明其正確性;

 

代碼:

 1 //***51nod1083
 2 #include <iostream>
 3 #include <stdio.h>
 4 #define ll long long
 5 using namespace std;
 6 
 7 int main(void){
 8     ll n;
 9     scanf("%lld", &n);
10     n-=1;
11     if(n&1){
12         ll k=(n-1)>>1;
13         for(int i=1; i<=n; i++){
14             printf("%d ", i);
15         }
16         printf("\n");
17         for(ll i=1; i<=n; i++){
18             ll cnt=(i*k)%n;
19             printf("%lld ", cnt?cnt:n);
20         }
21         printf("\n");
22     }else{
23         printf("0\n");
24     }
25     return 0;
26 }
View Code

 

posted @ 2017-05-01 18:34  geloutingyu  阅读(168)  评论(0编辑  收藏  举报