当前位置:网站首页>【练习-8】(Uva 246)10-20-30==模拟
【练习-8】(Uva 246)10-20-30==模拟
2022-07-06 09:26:00 【火焰车】
题意:
一个游戏。共52张牌(1~10中的数字)初始状态,按输入顺序放在 总堆里。然后从头开始,挨着拿7张,从左到右摆开,作为7堆。然后回到第一堆,以此循环着每次往一堆放一张。每放完一张牌,考虑下面的情况:
1.这一堆的头两张与尾一张之和等于10 or 20 or 30
2.这一堆的头一张与尾两张之和等于10 or 20 or 30
3.这一堆的尾三张之和等于10 or 20 or 30
若满足其中一个情况,则从这堆里取出这三张牌,放到总堆的尾部(注意要不改变这三张牌的头尾顺序)。多个情况满足时,优先考虑前面的。当某一堆恰好某一次取牌被取空了,则这一堆将永久被遗忘,不再往上发牌。问:最后的状态。若7个堆都空了,则Win。若总堆空了,则Loss。若陷入了无限循环,则为Draw然后输出步数。
#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)//情况1:两个头一个尾
{
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; //是否是10的倍数(可能取得的数的范围是3-30所以这样写没问题)
}
int situation2(deque<int>tmp)//情况2:一个头两个尾
{
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)//情况3:三个尾
{
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;
}
//因为是传参的函数,所以其操作不会影响到双端队列本身。
//这是对该操作可行性的判断。
int solve(deque<int>&tmp, deque<int>&all)
{
//模拟操作流程,这里是传引用,操作会影响双端队列本身。
if(tmp.size()<3)return 0;//不到三张牌无法操作。
if(situation1(tmp))
{
//如果某一个情况可行性判断通过,就要对其进行该操作。
//并且按照顺序把牌放到总的牌组里。
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];
//用来初始化牌的顺序。
vector<deque<int> > deq;
//用vector实际上约等于开一个deque的数组。
set< vector<deque<int> > > repeat;
//这个是来判断是否出现循环节(重复出现同一种情况)
for(int i=0;i<8;i++) deq.push_back(deque<int>());
//初始化“双端队列数组”即VECTOR双端队列
deque<int> &all = deq[7];
//这里为什么要直接让all与deq[7]挂钩而不是直接定义all呢?
//原因是要判断是否重复的时候也要考虑到现在牌组的顺序(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;
//记录步数(上面一步给每个牌堆一张牌,所以有七步)
int point=0;
//记录当前牌堆
while(1)
{
ans++;
int num=all.front(); all.pop_front();
deq[point].push_back(num);
while(solve(deq[point],all));
if(repeat.count(deq))
//这里是看是否已经出现过deq的排列,如果出现过了,就会无限重复。
//这里的重复的deq的排列是指 8个双端队列数组全部相同。
{
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);
//如果是该牌堆里没有牌了就跳过。
}
}
return 0;
}
挺有意思的。
边栏推荐
- 想应聘程序员,您的简历就该这样写【精华总结】
- Hospital privacy screen Industry Research Report - market status analysis and development prospect forecast
- 用C语言写网页游戏
- Alice and Bob (2021牛客暑期多校训练营1)
- Market trend report, technological innovation and market forecast of pneumonia drugs obtained by Chinese hospitals
- Research Report on medical toilet industry - market status analysis and development prospect forecast
- Gartner:关于零信任网络访问最佳实践的五个建议
- Research Report on printed circuit board (PCB) connector industry - market status analysis and development prospect forecast
- Opencv learning log 19 skin grinding
- Flink 使用之 CEP
猜你喜欢
STM32 how to use stlink download program: light LED running light (Library version)
STM32学习记录:玩转按键控制蜂鸣器和LED
STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)
ucore lab5
洛谷P1102 A-B数对(二分,map,双指针)
1010 things that college students majoring in it must do before graduation
STM32 learning record: input capture application
ucorelab3
Gartner:关于零信任网络访问最佳实践的五个建议
数据在内存中的存储&载入内存,让程序运行起来
随机推荐
STM32 learning record: input capture application
学习记录:串口通信和遇到的错误解决方法
0-1 knapsack problem (I)
ucorelab4
Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
0-1背包問題(一)
MATLAB综合练习:信号与系统中的应用
Cost accounting [13]
区间和------离散化
HDU-6025-Coprime Sequence(女生赛)
China's earthwork tire market trend report, technical dynamic innovation and market forecast
JS --- all basic knowledge of JS (I)
Cost accounting [21]
JS --- JS function and scope (II)
Opencv learning log 30 -- histogram equalization
B - 代码派对(女生赛)
Research Report on shell heater industry - market status analysis and development prospect forecast
ucore lab 2
JS --- BOM details of JS (V)
Accounting regulations and professional ethics [4]