现在的位置: 首页 > 综合 > 正文

Sicily 1003. Hit or Miss

2018年04月08日 ⁄ 综合 ⁄ 共 769字 ⁄ 字号 评论关闭

模拟题,上网看中文才弄懂题意,不难,记住要设最长循环时间,过了就算输。

#include <iostream>
#include <queue>
using namespace std;
int main(int argc, char const *argv[])
{
  int t,n,temp,cnt = 1;
  cin >> t;
  while(t--)
  {
     cin >> n;
     queue<int>card[11];
     int count[11],last[11],throwcard = 0, time = 0;    
     for(int i = 0; i < 52; i++)
     {
      cin >> temp;
      card[0].push(temp);
     }
     for(int i = 0; i < n; i++)
      count[i] = 1;
     while(throwcard < 52 && time <= 2000)
     {
      time++;
      for (int i = 0; i < n; ++i)
      {
        if(card[i].empty()) continue;
        if(card[i].front() == count[i])
        {
          last[i] = card[i].front();
          if(i==n-1) throwcard++;
          else card[i+1].push(card[i].front());

          card[i].pop();
        }
        else
        {
          card[i].push(card[i].front());
          card[i].pop();
        }
        count[i]++;
        count[i] = (count[i] == 14) ? 1 : count[i]%14;
      }
     }
     cout << "Case " << cnt++ << ": ";
     if(throwcard < 52) 
      cout << "unwinnable" ;
     else
      for(int i = 0; i < n; i++)
      {
        if(i==0) cout << last[i];
        else cout << " " << last[i];
      }
      cout << endl;
  }
  return 0;
}                                 

【上篇】
【下篇】

抱歉!评论已关闭.