zoukankan      html  css  js  c++  java
  • 【HDOJ】1466 计算直线的交点数

    找了个规律。

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <string.h>
     4 
     5 #define MAXN 21
     6 
     7 int buf[MAXN][150];
     8 int lens[MAXN];
     9 
    10 int comp(const void *a, const void *b) {
    11     return *(int *)a - *(int *)b;
    12 }
    13 
    14 int main() {
    15     int i, j, k, tmp, p, flg;
    16     memset(lens, 0, sizeof(lens));
    17     memset(buf, 0, sizeof(buf));
    18     lens[0] = 1;
    19     lens[1] = 1;
    20     lens[2] = 2;
    21     buf[2][1] = 1;
    22 
    23     for (i=3; i<MAXN; ++i) {
    24         lens[i] = 1;
    25         for (j=1; j<i; ++j) {
    26             for (k=0; k<lens[j]; ++k) {
    27                 tmp = (i-j)*j+buf[j][k];
    28                 flg = 1;
    29                 for (p=lens[i]-1; p>=0; --p) {
    30                     if (buf[i][p] == tmp) {
    31                         flg = 0;
    32                         break;
    33                     }
    34                 }
    35                 if (flg)
    36                     buf[i][lens[i]++] = tmp;
    37             }
    38         }
    39         qsort(buf[i], lens[i], sizeof(int), comp);
    40     }
    41 
    42     while (scanf("%d", &k) != EOF) {
    43         printf("%d", buf[k][0]);
    44         for (i=1; i<lens[k]; ++i) {
    45             if (buf[k][i] != buf[k][i-1])
    46                 printf(" %d", buf[k][i]);
    47         }
    48         printf("
    ");
    49     }
    50 
    51     return 0;
    52 }
  • 相关阅读:
    POJ
    FZU
    HDU
    HDU
    HDU
    HDU
    Educational Codeforces Round 84 E. Count The Blocks
    B Boundary(由弦求圆)
    D. Maximum Sum on Even Positions(翻转1次,求最大偶数位和)
    E. DeadLee(思维,拓扑图处理)
  • 原文地址:https://www.cnblogs.com/bombe1013/p/3767678.html
Copyright © 2011-2022 走看看