当前位置:网站首页>[exercise-8] (UVA 246) 10-20-30== simulation
[exercise-8] (UVA 246) 10-20-30== simulation
2022-07-06 15:56:00 【Flame car】
The question :
A game . common 52 card (1~10 Number in ) The initial state , Put it in the order of input In the total pile . Then start from the beginning , Take it next to each other 7 Zhang , Swing from left to right , As 7 Pile up . Then go back to the first pile , In this cycle, stack one sheet at a time . After each card is played , Consider the following :
1. The sum of the first two and the last one in this pile is equal to 10 or 20 or 30
2. The sum of the first and last two sheets of this pile is equal to 10 or 20 or 30
3. The sum of the last three sheets of this pile is equal to 10 or 20 or 30
If one of these conditions is satisfied , Then take these three cards out of the pile , Put it at the end of the total heap ( Be careful not to change the order of the three cards ). When multiple situations are satisfied , Give priority to the front . When a pile of cards is emptied just once , Then this pile will be forgotten forever , No more upward licensing . ask : The final state . if 7 The pile is empty , be Win. If the total stack is empty , be Loss. If you fall into an infinite loop , Then for Draw Then output the number of steps .
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
const ll mod = 1e9+7;
const int maxn = 1e3+5;
int situation1(deque<int>tmp)// situation 1: Two heads and one tail
{
int sum=0;
sum+=tmp.front(); tmp.pop_front();
sum+=tmp.front(); tmp.pop_front();
sum+=tmp.back(); tmp.pop_back();
return sum%10==0; // Whether it is 10 Multiple ( The range of possible numbers is 3-30 So it's no problem to write like this )
}
int situation2(deque<int>tmp)// situation 2: One head and two tails
{
int sum=0;
sum+=tmp.front(); tmp.pop_front();
sum+=tmp.back(); tmp.pop_back();
sum+=tmp.back(); tmp.pop_back();
return sum%10==0;
}
int situation3(deque<int>tmp)// situation 3: Three tails
{
int sum=0;
sum+=tmp.back(); tmp.pop_back();
sum+=tmp.back(); tmp.pop_back();
sum+=tmp.back(); tmp.pop_back();
return sum%10==0;
}
// Because it's a function that passes parameters , Therefore, its operation will not affect the double ended queue itself .
// This is the judgment of the feasibility of this operation .
int solve(deque<int>&tmp, deque<int>&all)
{
// Simulate the operation process , Here is a quote , The operation will affect the double ended queue itself .
if(tmp.size()<3)return 0;// Less than three cards cannot be operated .
if(situation1(tmp))
{
// If the feasibility judgment of a certain situation passes , It is necessary to perform this operation .
// And put the cards in the total deck in order .
int s1=tmp.front(); tmp.pop_front();
int s2=tmp.front(); tmp.pop_front();
int s3=tmp.back(); tmp.pop_back();
all.push_back(s1);
all.push_back(s2);
all.push_back(s3);
return 1;
}
else if(situation2(tmp))
{
int s1=tmp.front(); tmp.pop_front();
int s2=tmp.back(); tmp.pop_back();
int s3=tmp.back(); tmp.pop_back();
all.push_back(s1);
all.push_back(s3);
all.push_back(s2);
return 1;
}
else if(situation3(tmp))
{
int s1=tmp.back(); tmp.pop_back();
int s2=tmp.back(); tmp.pop_back();
int s3=tmp.back(); tmp.pop_back();
all.push_back(s3);
all.push_back(s2);
all.push_back(s1);
return 1;
}
return 0;
}
int main()
{
int a[52];
// Used to initialize the order of cards .
vector<deque<int> > deq;
// use vector In fact, it is about equal to opening a deque Array of .
set< vector<deque<int> > > repeat;
// This is to judge whether there is a circular section ( Repeat the same situation )
for(int i=0;i<8;i++) deq.push_back(deque<int>());
// initialization “ Double ended queue array ” namely VECTOR deque
deque<int> &all = deq[7];
// Why should we directly let all And deq[7] Hook up rather than directly define all Well ?
// The reason is that the order of the current deck should also be considered when judging whether it is repeated (all)
while(cin>>a[0]&&a[0])
{
all.clear();repeat.clear();
for(int i=1;i<52;i++) cin>>a[i];
for(int i=0;i<52;i++) all.push_back(a[i]);
for(int i=0;i<7;i++)
{
deq[i].clear();
int num=all.front();all.pop_front();
deq[i].push_back(num);
}
int ans=7;
// Record the steps ( In the above step, stack one card for each card , So there are seven steps )
int point=0;
// Record the current deck
while(1)
{
ans++;
int num=all.front(); all.pop_front();
deq[point].push_back(num);
while(solve(deq[point],all));
if(repeat.count(deq))
// Here is to see if it has appeared deq Permutation , If it happens , Will repeat indefinitely .
// The repetition here deq The arrangement of means 8 Two double ended queue arrays are all the same .
{
printf("Draw: %d\n",ans);
break;
}
repeat.insert(deq);
if(all.size()==0)
{
printf("Loss: %d\n",ans);
break;
}
if(all.size()==52)
{
printf("Win : %d\n",ans);
break;
}
do{
point=(point+1)%7;
}while(deq[point].size()==0);
// If there are no cards in the stack, skip .
}
}
return 0;
}
That's interesting .
边栏推荐
- Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
- Opencv learning log 16 paperclip count
- Research Report on printed circuit board (PCB) connector industry - market status analysis and development prospect forecast
- Accounting regulations and professional ethics [3]
- Information security - threat detection - detailed design of NAT log access threat detection platform
- 【练习-6】(Uva 725)Division(除法)== 暴力
- 渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
- 差分(一维,二维,三维) 蓝桥杯三体攻击
- China's salt water membrane market trend report, technological innovation and market forecast
- Learning record: understand systick system timer and write delay function
猜你喜欢
Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class
Matlab comprehensive exercise: application in signal and system
TCP的三次握手与四次挥手
Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs
入门C语言基础问答
力扣刷题记录
C语言数组的概念
Ball Dropping
B - 代码派对(女生赛)
随机推荐
Learning record: Tim - Basic timer
【练习-7】Crossword Answers
MySQL授予用户指定内容的操作权限
7-1 懂的都懂 (20 分)
【练习-10】 Unread Messages(未读消息)
The most complete programming language online API document
cs零基础入门学习记录
C语言数组的概念
Research Report on market supply and demand and strategy of geosynthetics industry in China
Learning record: USART serial communication
Cost accounting [13]
初入Redis
Information security - Analysis of security orchestration automation and response (soar) technology
程序员的你,有哪些炫技的代码写法?
STM32 how to use stlink download program: light LED running light (Library version)
Cost accounting [19]
Printing quality inspection and verification system Industry Research Report - market status analysis and development prospect forecast
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
毕业才知道IT专业大学生毕业前必做的1010件事
C语言学习笔记