zoukankan      html  css  js  c++  java
  • Ducci 队列 -基础queue,set

    https://vjudge.net/contest/185301#problem/B

    用队列记录,set的不重复性来判断

     1 //#include<bits/stdc++.h>
     2 #include<stdio.h>
     3 #include<string.h>
     4 #include<math.h>
     5 #include<iostream>
     6 #include<stdlib.h>
     7 #include<algorithm>
     8 #include<queue>
     9 #include<vector>
    10 #include<string>
    11 #include<set>
    12 #include<cctype>
    13 #include<sstream>
    14 #define mem(a) memset(a,0,sizeof(a))
    15 #define LL long long
    16 #define ull unsigned long long
    17 #define inf 0x3f3f3f3f
    18 using namespace std;
    19 const int N=998244353;
    20 int n,k;
    21 char s[105],ss[105];
    22 int a[10500],b[105];
    23 LL f[1005][2010][2];
    24 int abs(int a)
    25 {
    26   if(a<0) return -a;
    27   return a;
    28 }
    29 int main()
    30 {
    31     int t,v,c;
    32  scanf("%d",&t);
    33  while(t--)
    34  {
    35      scanf("%d",&n);
    36      queue<int>q;
    37      set<int>s;
    38      int flag=0;
    39      for(int i=1;i<=n;i++)
    40      {
    41          scanf("%d",&v);
    42          q.push(v);
    43      }
    44      for(int i=0;i<1000;i++)
    45      {
    46        for(int j=1;j<=n;j++)
    47         {
    48          if(j==1)
    49          {
    50           int u=q.front();
    51           int k=q.back();
    52           c=abs(u-k);
    53          }
    54          int u=q.front();
    55          q.pop();
    56          if(j<n)
    57          {
    58             int k=q.front();
    59             q.push(abs(u-k));
    60             s.insert(abs(u-k));
    61          }
    62          if(j==n)
    63          {
    64              q.push(c);
    65              s.insert(c);
    66          }
    67         }
    68         if(s.size()==1)
    69         {
    70             flag=1;
    71             break;
    72         }
    73          s.clear();//!!
    74      }
    75      while(!q.empty())
    76      {
    77         q.pop(); //!!
    78      }
    79      if(flag==1) printf("ZERO
    ");
    80      else printf("LOOP
    ");
    81  }
    82  return 0;
    83 }
    View Code
  • 相关阅读:
    Vue监听器、过滤器
    Vue生命周期、计算属性
    数组去重
    ES6总结
    学习笔记--html篇(1)
    学习整理--flex布局(1)
    对块作用域与变量函数提升再添新认识
    了解使用web workers
    js中的事件循环模型与特殊的定时器
    操作系统、浏览器与js之间的一些概念与联系
  • 原文地址:https://www.cnblogs.com/XXrll/p/10334687.html
Copyright © 2011-2022 走看看