当前位置:网站首页>[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 .
边栏推荐
- 【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)
- Gartner: five suggestions on best practices for zero trust network access
- 力扣刷题记录--完全背包问题(一)
- Research Report on market supply and demand and strategy of China's land incineration plant industry
- MATLAB综合练习:信号与系统中的应用
- STM32 how to use stlink download program: light LED running light (Library version)
- Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
- D - Function(HDU - 6546)女生赛
- 信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
- 区间和------离散化
猜你喜欢
动态规划前路径问题优化方式
Learning record: Tim - Basic timer
Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs
数据在内存中的存储&载入内存,让程序运行起来
入门C语言基础问答
C语言学习笔记
信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
差分(一维,二维,三维) 蓝桥杯三体攻击
Information security - threat detection engine - common rule engine base performance comparison
1010 things that college students majoring in it must do before graduation
随机推荐
【练习-11】4 Values whose Sum is 0(和为0的4个值)
Gartner:关于零信任网络访问最佳实践的五个建议
CEP used by Flink
Learning record: Tim - Basic timer
C语言是低级和高级的分水岭
Penetration test (7) -- vulnerability scanning tool Nessus
通俗地理解什么是编程语言
信息安全-安全编排自动化与响应 (SOAR) 技术解析
渗透测试 ( 1 ) --- 必备 工具、导航
TCP的三次握手与四次挥手
【练习-8】(Uva 246)10-20-30==模拟
Opencv learning log 15 count the number of solder joints and output
Research Report on market supply and demand and strategy of China's earth drilling industry
Penetration test (1) -- necessary tools, navigation
Information security - threat detection - detailed design of NAT log access threat detection platform
C语言学习笔记
Cost accounting [21]
HDU-6025-Coprime Sequence(女生赛)
Shell脚本编程
C语言数组的概念