当前位置:网站首页>[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 .
边栏推荐
- 【练习-6】(Uva 725)Division(除法)== 暴力
- China's earthwork tire market trend report, technical dynamic innovation and market forecast
- 渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
- Market trend report, technical innovation and market forecast of Chinese hospital respiratory humidification equipment
- JS调用摄像头
- Information security - threat detection engine - common rule engine base performance comparison
- Research Report of exterior wall insulation system (ewis) industry - market status analysis and development prospect prediction
- D - Function(HDU - 6546)女生赛
- China's peripheral catheter market trend report, technological innovation and market forecast
- 洛谷P1102 A-B数对(二分,map,双指针)
猜你喜欢

B - 代码派对(女生赛)

Learning record: USART serial communication

Learning record: how to perform PWM output

7-1 懂的都懂 (20 分)

Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures

VS2019初步使用

【高老师UML软件建模基础】20级云班课习题答案合集

毕业才知道IT专业大学生毕业前必做的1010件事

【高老师软件需求分析】20级云班课习题答案合集

Nodejs+vue online fresh flower shop sales information system express+mysql
随机推荐
SSM框架常用配置文件
Cost accounting [16]
0 - 1 problème de sac à dos (1)
Matlab example: two expressions of step function
Research Report of exterior wall insulation system (ewis) industry - market status analysis and development prospect prediction
Web based photo digital printing website
动态规划前路径问题优化方式
渗透测试 ( 4 ) --- Meterpreter 命令详解
Perform general operations on iptables
渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
区间和------离散化
信息安全-安全编排自动化与响应 (SOAR) 技术解析
Opencv learning log 13 corrosion, expansion, opening and closing operations
Research Report of cylindrical grinder industry - market status analysis and development prospect forecast
TCP的三次握手与四次挥手
Opencv learning log 32 edge extraction
Research Report on printed circuit board (PCB) connector industry - market status analysis and development prospect forecast
Accounting regulations and professional ethics [4]
Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
【练习-9】Zombie’s Treasure Chest