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\n");
80      else printf("LOOP\n");
81  }
82  return 0;
83 }
View Code

 

转载于:https://www.cnblogs.com/XXrll/p/10334687.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
think-queue是一个基于ThinkPHP5框架的消息队列扩展,可以将耗时的任务异步处理,提高系统的并发能力和稳定性。以下是think-queue的介绍和演示: 介绍: 1. think-queue的安装:可以通过composer安装,具体命令为:composer require topthink/think-queue。 2. think-queue的配置:需要在config/queue.php文件中进行配置,包括连接信息、队列名称、超时时间等。 3. think-queue的使用:可以通过php think queue:listen命令启动队列监听器,也可以通过php think queue:work命令启动队列处理器。 演示: 假设我们需要发送邮件,但是由于邮件发送需要连接SMTP服务器,因此会比较耗时。我们可以将邮件发送任务放入消息队列中异步处理,以提高系统的并发能力和稳定性。以下是一个简单的think-queue邮件发送示例: 1.定义邮件发送任务类: ```php namespace app\queue\job; use think\queue\Job; use PHPMailer\PHPMailer\PHPMailer; class SendMail { public function fire(Job $job, $data) { $mail = new PHPMailer(); // 邮件发送代码 if ($mail->send()) { // 邮件发送成功,删除任务 $job->delete(); } else { // 邮件发送失败,重新放入队列 $job->release(60); } } } ``` 2.将邮件发送任务加入消息队列: ```php use think\Queue; use app\queue\job\SendMail; // 将邮件发送任务加入消息队列 Queue::push(new SendMail($data)); ``` 3.启动队列监听器: ```shell php think queue:listen ``` 以上示例中,我们定义了一个SendMail类作为邮件发送任务,将其加入消息队列中异步处理。在fire方法中,我们使用PHPMailer类发送邮件,如果发送成功则删除任务,否则重新放入队列。最后,我们通过php think queue:listen命令启动队列监听器,等待任务的到来。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值