zoukankan      html  css  js  c++  java
  • CCF 201803-2 碰撞的小球

     1 #include <iostream>
     2 //#include <bits/stdc++.h>
     3 #include <string>
     4 
     5 using namespace std;
     6 
     7 typedef struct {
     8     int location;
     9     int foreOrback;
    10 }table;
    11 
    12 bool isequal(table *tab,int i,int n,int L);
    13 void change(table &tt);
    14 
    15 void move(table *tab,int n,int L)
    16 {
    17     for(int i=0;i<n;i++)
    18     {
    19         if(isequal(tab,i,n,L))
    20             tab[i].location+=tab[i].foreOrback;
    21         else
    22         {
    23             //change(tab[i]);
    24             tab[i].location+=tab[i].foreOrback;
    25         }
    26     }
    27 }
    28 
    29 bool isequal(table *tab,int i,int n,int L)
    30 {
    31     if(tab[i].location==L&&tab[i].foreOrback==1)
    32     {
    33         tab[i].foreOrback=-1;
    34         return false;
    35     }
    36     else if(tab[i].location==0&&tab[i].foreOrback==-1)
    37     {
    38         tab[i].foreOrback=1;
    39         return false;
    40     }
    41     for(int j=0;j<n;j++)
    42     {
    43         if(j!=i)
    44         {
    45             if(tab[j].location==tab[i].location)
    46             {
    47                 change(tab[j]);
    48                 change(tab[i]);
    49                 return false;
    50             }
    51         }
    52     }
    53     return true;
    54 }
    55 
    56 void change(table &tt)
    57 {
    58     if(tt.foreOrback==-1)
    59         tt.foreOrback=1;
    60     else
    61         tt.foreOrback=-1;
    62 }
    63 
    64 int main()
    65 {
    66     int n,L,t;
    67     cin>>n>>L>>t;
    68     table *s;
    69     s=new table[n];
    70     for(int i=0;i<n;i++)
    71     {
    72         cin>>s[i].location;
    73         s[i].foreOrback=1;
    74     }
    75     while(t--)
    76     {
    77         move(s,n,L);
    78     }
    79     for(int i=0;i<n;i++)
    80     {
    81         if(i==0)
    82             cout<<s[i].location;
    83         else
    84             cout<<" "<<s[i].location;
    85     }
    86     return 0;
    87 }
  • 相关阅读:
    mysql数据库
    Mysql之sql语句操作
    mysql修改root密码的多种方法
    kvm虚拟化
    清华AIOps算法:KPI聚类
    有点扯的预测方法
    内网安全运营的逻辑体系架构
    SpringBoot定时消费Kafka消息
    kafka的consumer消费能力很低的情况下的处理方案
    Kafka_Kafka 消费者 偏移量 与 积压 查询脚本 kafka-consumer-groups.sh
  • 原文地址:https://www.cnblogs.com/-Asurada-/p/14236432.html
Copyright © 2011-2022 走看看