当前位置:网站首页>[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 .
边栏推荐
- 【练习-2】(Uva 712) S-Trees (S树)
- 渗透测试 ( 8 ) --- Burp Suite Pro 官方文档
- Learning record: Tim - Basic timer
- Report on the market trend, technological innovation and market forecast of printing and decorative paper in China
- Record of brushing questions with force deduction -- complete knapsack problem (I)
- Optimization method of path problem before dynamic planning
- China earth moving machinery market trend report, technical dynamic innovation and market forecast
- Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
- 渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
- Record of force deduction and question brushing
猜你喜欢
渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
毕业才知道IT专业大学生毕业前必做的1010件事
Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
Optimization method of path problem before dynamic planning
Gartner: five suggestions on best practices for zero trust network access
Learning record: use stm32f1 watchdog
Learning record: how to perform PWM output
Information security - threat detection engine - common rule engine base performance comparison
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
Record of force deduction and question brushing
随机推荐
X-forwarded-for details, how to get the client IP
Opencv learning log 32 edge extraction
Information security - security professional name | CVE | rce | POC | Vul | 0day
Interesting drink
【练习-6】(Uva 725)Division(除法)== 暴力
入门C语言基础问答
Cost accounting [17]
D - Function(HDU - 6546)女生赛
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
HDU-6025-Coprime Sequence(女生赛)
Research Report on market supply and demand and strategy of Chinese graphic screen printing equipment industry
想应聘程序员,您的简历就该这样写【精华总结】
Opencv learning log 33 Gaussian mean filtering
【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)
Accounting regulations and professional ethics [4]
STM32 learning record: LED light flashes (register version)
Determine the Photo Position
C语言数组的概念
China's earthwork equipment market trend report, technical dynamic innovation and market forecast
Cost accounting [13]