zoukankan      html  css  js  c++  java
  • 3331=数据结构实验之链表八:Farey序列

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 struct node
     4 {
     5     int date1,date2;
     6     struct node*next;
     7 } node;
     8 int main()
     9 {
    10     struct node*p,*head,*end,*q;
    11     head=(struct node*)malloc(sizeof(struct node));
    12     head->next=NULL;
    13     end=head;
    14     int n,i;
    15     scanf("%d",&n);
    16     p=(struct node*)malloc(sizeof(struct node));
    17     p->next=NULL;
    18     q=(struct node*)malloc(sizeof(struct node));
    19     q->next=NULL;
    20     head->next=p;
    21     p->next=q;
    22     q->next=NULL;
    23     p->date1=0;
    24     p->date2=1;
    25     q->date1=1;
    26     q->date2=1;
    27     for(i=1; i<=n; i++)
    28     {
    29         end=head->next;
    30         while(end->next!=NULL)
    31         {
    32             p=end->next;
    33             if((p->date2+end->date2)<=i)
    34             {
    35                 q=(struct node*)malloc(sizeof(struct node));
    36                 q->date1=end->date1+p->date1;
    37                 q->date2=end->date2+p->date2;
    38                 q->next=NULL;
    39                 end->next=q;
    40                 q->next=p;
    41                 end=end->next->next;
    42             }
    43             else
    44             {
    45                 end=end->next;
    46             }
    47         }
    48     }
    49 
    50     p=head->next;
    51     int mark=0;
    52     for(; p!=NULL; p=p->next)
    53     {
    54         if(mark!=0)printf("	");
    55         mark++;
    56         printf("%d/%d",p->date1,p->date2);
    57         if(mark==10)printf("
    "),mark=0;
    58 
    59     }
    60     return 0;
    61 }
  • 相关阅读:
    28完全背包+扩展欧几里得(包子凑数)
    HDU 3527 SPY
    POJ 3615 Cow Hurdles
    POJ 3620 Avoid The Lakes
    POJ 3036 Honeycomb Walk
    HDU 2352 Verdis Quo
    HDU 2368 Alfredo's Pizza Restaurant
    HDU 2700 Parity
    HDU 3763 CDs
    POJ 3279 Fliptile
  • 原文地址:https://www.cnblogs.com/Angfe/p/11638484.html
Copyright © 2011-2022 走看看