2016亚洲区域赛现场赛北京赛区e题

2016 ACM青岛区域赛题解 A 水题,直接暴力模拟即可。 #include #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 const int maxn=40000; typedef long long ll; int main(int argc, char const *argv[]) { int T; scanf("%d",&T); while(T--){ 阅读详情

Problem E. What a Ridiculous Election
Description
In country Light Tower, a presidential election is going on. There are two candidates, Mr. X1 and Mr. X2, and both of them are not like good persons. One is called a liar and the other is called a maniac. They tear(Chinese English word, means defame) each other on TV face to face, on newspaper, on internet…….on all kinds of media. The country is tore into two parts because the people who support X1 are almost as many as the people who support X2.
After the election day, X1 and X2 get almost the same number of votes. No one gets enough votes to win. According to the law of the country, the Great Judge must decide who will be the president. But the judge doesn’t want to offend half population of the country, so he randomly chooses a 6 years old kid Tom and authorize him to pick the president. Sounds weird? But the democracy in Light Tower is just like that.
The poor or lucky little kid Tom doesn’t understand what is happening to his country. But he has his way to do his job. Tom’s ao shu(Chinese English word, means some kind of weird math for kids) teacher just left him a puzzle a few days ago, Tom decide that he who solve that puzzle in a better way will be president. The ao shu teacher’s puzzle is like this:
Given a string which consists of five digits(‘0’-‘9’), like “02943”, you should change “12345” into it by as few as possible operations. There are 3 kinds of operations:
1. Swap two adjacent digits.
2. Increase a digit by one. If the result exceed 9, change it to it modulo 10.
3. Double a digit. If the result exceed 9, change it to it modulo 10.
You can use operation 2 at most three times, and use operation 3 at most twice.
As a melon eater(Chinese English again, means bystander), which candidate do you support? Please help him solve the puzzle.
Input
There are no more than 100,000 test cases.
Each test case is a string which consists of 5 digits.
Output
For each case, print the minimum number of operations must be used to change “12345” into the given string. If there is no solution, print -1.
Sample Input
12435
99999
12374
Sample Output
1
-1
3
题意:给你一个长度为5的字符串,每个都是数字,然后给你下面三种操作
操作一:交换相连的两个数字
操作二:将一个数字加一,如果大于9,与10取模。此操作最多3次
操作三:将一个数字乘以二,如果大于9,与10取模。此操作最多2次
问你能不能把“12345”变成给定的字符,只能通过上面三种操作,且每一种操作次数不能超过规定次数。

解题思路:通过bfs处理每一种状态的后续状态,然后把所有的状态记录下来,直接查询就行,也就是把“12345”能够达到的所有状态都处理出来。ans[i][j][k]表示从字符串“12345”到达字符串“xxxxx”(把xxxxx当成整数得到的值为i)操作2的剩余次数为j,操作3剩余的次数为k的最小步骤数。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
char s[10];
int ten[10];
struct node{
    string num;
    int step;
    int inc;
    int dou;
};
int ans[maxn][5][5];
bool visit[maxn][5][5];
queue<node> Q;
node nx;
int transfer(string p)
{
    int sum = 0;
    int j = 0;
    for(int i = 4; i >= 0; i--)
    {
        sum += (p[i] - '0')*ten[j++];
    }
    return sum;
}
void bfs(node n0)
{
    Q.push(n0);
    while(!Q.empty())
    {
        node n = Q.front();
        Q.pop();

        int value = transfer(n.num);
        ans[value][n.inc][n.dou] = min(ans[value][n.inc][n.dou],n.step);
        visit[value][n.inc][n.dou] = true;

        node x;
        for(int i = 0; i <= 3; i++)
        {
            x.num = n.num;
            x.num[i] = n.num[i + 1];
            x.num[i + 1] = n.num[i];
            value = transfer(x.num);
            if(!visit[value][n.inc][n.dou])
            {
                x.step = n.step + 1;
                x.inc = n.inc;
                x.dou = n.dou;
                Q.push(x);
                visit[value][n.inc][n.dou] = true;
            }
        }
        if(n.inc > 0)
        {
            for(int i = 0; i <= 4; i++)
            {
               x.num = n.num;
               int term = n.num[i] - '0';
               term++;
               term %= 10;
               x.num[i] = term + '0';
               value = transfer(x.num);
               if(!visit[value][n.inc - 1][n.dou])
               {
                  x.step = n.step + 1;
                  x.inc = n.inc - 1;
                  x.dou = n.dou;
                  Q.push(x);
                  visit[value][n.inc - 1][n.dou] = true;
               }
            }
        }
        if(n.dou > 0)
        {
              for(int i = 0; i <= 4; i++)
              {
                 x.num = n.num;
                 int term = n.num[i] - '0';
                 term *= 2;
                 term %= 10;
                 x.num[i] = term + '0';
                 value = transfer(x.num);
                 if(!visit[value][n.inc][n.dou - 1])
                 {
                   x.step = n.step + 1;
                   x.inc = n.inc;
                   x.dou = n.dou - 1;
                   Q.push(x);
                   visit[value][n.inc][n.dou - 1] = true;
                 }
              }
        }
    }
}
void init()
{
    while(!Q.empty()) Q.pop();
    nx.step = 0;
    nx.inc = 3;
    nx.dou = 2;
    nx.num = "12345";
    ten[0] = 1;
    for(int i = 1; i <= 6; i++)
    {
        ten[i] = ten[i - 1]*10;
    }
    memset(visit,false,sizeof(visit));
    memset(ans,inf,sizeof(ans));

}
int main()
{
    init();
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    bfs(nx);

    while(~scanf("%s",s))
    {
        node sx;
        sx.num = nx.num;
        for(int i = 0; i <= 4; i++)
        {
            sx.num[i] = s[i];
        }
        int res = transfer(sx.num);
        //cout<<res<<endl;
        int Min = inf;
        for(int i = 0; i <= 3; i++)
        {
            for(int j = 0; j <= 2; j++)
            {
                //cout<<ans[res][i][j]<<endl;
                Min = min(Min,ans[res][i][j]);
            }
        }
        if(Min == inf) printf("-1\n");
        else printf("%d\n",Min);
    }
    return 0;
}
Seven Segment Display(数位dp) A seven segment display, or seven segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix displays. Seven segment 阅读详情

相关推荐

HDU6155(dp + 线段树区间更新 + 矩阵性质)

Subsequence Count Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others) Total Submission(s): 304    Accepted Submission(s): 126 Problem Description Given a

creatorx的博客 900

2016 ACM-ICPC 亚洲区域赛北京站E题 What a Ridiculous Election (BFS预处理)

Problem E. What a Ridiculous Election Description In country Light Tower, a presidential election is going on. There are two candidates,  Mr. X1 and Mr. X2, and both of them are not like good pers

Sizaif's 小屋 1666

WorkBuddy 实战:规则、记忆与 Skill 配置全攻略

AI工作台正成为连接大模型与真实业务的桥梁,其核心价值在于将零散AI能力封装为可复用的工作流。WorkBuddy作为典型智能体入口,通过自定义规则、跨对话记忆与Skill扩展,解决AI“失忆”和“不懂行话”等痛点。从概念到实践,掌握安装避坑、缓存目录调整、知识库挂载等基础操作后,用户可在客服话术生成、文献综述、重复任务自动执行等场景中显著提升效率。本文结合Docker私有化部署与安全审核要点,系统拆解WorkBuddy从入门到进阶的完整路径,帮助团队将AI工具沉淀为可维护的流程资产。

weixin_29053073的博客 465

Hihocoder 1426 E. What a Ridiculous Election (BFS)

Problem12345 可以经过若干次操作转换为其它五位数。操作分三种,分别为: 交换相邻两数 选择一位 +1,若大于 9 ,则对 10 取模 选择一位 *2 ,若大于 9,则对 10 取模 其中操作 2 最大进行 3 次,操作 3 最多进行 2 次。对于给定的五位数,求 12345 在满足限制条件情况下,最少通过几步操作可以转换为目标五位数。若不可能,则输出 -1 。解题思路BFS 预处理产生

DorMOUSENone的博客 1559

苍穹外卖项目面试总结话术

美食速递这个项目最初是我参与制作的大创项目,是一款为中南学生提供校园外卖送至宿舍服务的软件,包含系统管理后台和小程序端两部分。其中系统管理后台主要提供给食堂内部员工使用,可以对食堂各个窗口、员工、订单、菜品等进行维护管理;小程序端可以在线浏览菜品、添加购物车、下单等,由学生兼职做跑腿送餐上门服务。这是个前后端分离的项目,我主要是负责后端的用户登录、员工管理,菜品管理,订单管理模块的编码实现。

qq_45195447的博客 1万+

计算机考研408复试题汇总

TCP连接是全双工的,两端都可以先挥手 其中一端完成数据发送任务后,发送一个FIN包来终止,另一端针对这个FIN包回复确认包, 直到另一端也发送请求终止数据包FIN,另一端作出确认应答,并且还要发送一个ACK=1表示确认号有效,如果没有收到这个就可以进行重传.

ca1m4n的博客 1万+

2016 ACM/ICPC 区域赛(北京) E 题 bfs

https://vjudge.net/problem/UVALive-7672 题意 输入一个五位数n 问由12345变到n的操作最少次数 不可达输出-1 有三种操作 1.交换相邻的位置 次数不限制 2.使某一位上的数字+1 最多使用三次 (mod 10) 3.使某一位上的数字*2 最多使用两次 (mod 10) 解析 很容易想到预处理,然后O(1)...

dianxue5904的博客 197

Trae编程工具Cline插件深度集成与Claude 3.7 API Key高级配置实战

本文详细介绍了如何在Trae编程工具中深度集成Cline插件并配置Claude 3.7 API Key的高级技巧。通过实战案例,展示了如何提升代码补全质量、实现多轮对话记忆及自定义代理设置,特别适合全栈工程师和需要私有化AI服务的团队。文章还涵盖了安装流程、API Key获取方式及企业级部署的最佳实践。

weixin_28829903的博客 444

2016北京赛区网赛C(模拟)

2016北京赛区网赛C(模拟)

Ema1997的博客 437

电动汽车远程监控与诊断软件:BMW ConnectedDrive EV远程监控二次开发_7.数据安全与隐私保护

数据加密是保护数据安全的重要手段之一。在电动汽车远程监控与诊断软件中,加密技术可以确保数据在传输过程中的安全性和完整性。常见的加密技术包括对称加密和非对称加密。

zhubeibei168的博客 891

AI测试干货:让大语言模型稳定输出 JSON 的四种实现方案

用大语言模型做测试用例生成、数据提取时,最头疼的就是让它老老实实返回 JSON。你以为它会给你 `{"name":"张三"}`,结果它来一句"好的,这是生成结果:```json...",或者干脆在 JSON 里加注释,直接把你的 `json.loads()` 干崩溃。 模型本质上是个话痨,天生爱解释。但我们要的是结构化数据,不是聊天记录。我整理了四种实战方案,从最简单的提示词技巧到工程化框架,覆盖了从快速验证到生产环境的各种场景。

blues_C的博客 965

2016亚洲区域赛现场赛北京赛区k题

Problem K. JiLi Number Description Driver Ji likes the digit “1”. He has an accumulator which shows the sum of input number. He lists all of positive number no more than N and starts counting from on

creatorx的博客 1854

02-Redis 核心特性与数据结构详解:揭秘高性能的技术内核

本文深度拆解 Redis 高性能的技术内核:揭秘其凭“内存存储 + C 语言开发” 实现微秒级延迟、10 万 + QPS 的性能优势;详解 5 种基础数据类型(String/Hash 等)与 4 种扩展数据类型(Stream/Geospatial 等)的特性及场景;还介绍多语言支持、RDB/AOF 持久化、主从复制 / 哨兵 / 集群等高可用方案,助读者掌握 Redis 技术核心与实践逻辑。

蜗牛老师,专注编程领域 1003

2016亚洲区域赛现场赛北京赛区f题

Problem F. What a Simple Research Description Peking University Student Folk Music Band has a history of more than 90 years. They play Chinese traditional music by Chinese traditional instruments, su

creatorx的博客 569

FPGA实现串口升级及MultiBoot(九)BPI FLASH相关实例演示

与SPI相关知识并没有什么太多区别(别杠硬件或者架构上),相关知识点都在上面指出,大家有什么其他需要注意点,欢迎留言讨论。关于“四样错误”就不演示了,没什么太大区别,下一讲我们开始串口升级。PS:为了扩展ICAPE2原语的使用,在原来的基础上增加了几个常用FPGA ID,并在触发启动时候增加了可选电平触发或上升/下降沿触发(例化IP时选择),新版本号V1.1。

OpenFPGA的博客 1459

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

2016 ACM/ICPC Asia Regional Dalian Online 大连区域赛部分题解

1007-Friends and Enemies用完全二分图表示朋友和敌人的关系,每个部分里的人和同一部分的其他人都是敌人,而与另一部分的人都是朋友,这样二分图的边就是不同鹅卵石的最大种类数,然后将这个与给出的种类数比较即可。//1007 #include <cstdio>int main(int argc, char const *argv[]) { long long m, n;

Collider 1193

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

hihoCoder 1426 : What a Ridiculous Election(总统夶选)

hihoCoder #1426 : What a Ridiculous Election(总统夶选) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述   In country Light Tower, a presidential election is going on. There are two candid...

200

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

2016 ICPC北京 problem E.What a Ridiculous Election(预处理bfs)

What a Ridiculous Election In country Light Tower, a presidential election is going on. There are two candidates, Mr. X1 and Mr. X2, and both of them are not like good persons. One is called a liar a...

yu121380的博客 365

hihocoder1426 What a Ridiculous Election(bfs预处理)

The 2016 ACM-ICPC Asia Beijing Regional Contest 2016 ACM-ICPC 亚洲区域赛北京站E题   Problem E. What a Ridiculous Election Description In country Light Tower, a presidential election is going on. There a

KeyboardPianist的博客 1750

UVALive 7672 - What a Ridiculous Election (暴力)

In country Light Tower, a presidential election is going on. There are two candidates, Mr. X1 andMr. X2, and both of them are not like good persons. One is called a liar and the other is called ama

Mr_Treeeee的博客 904

2018北大暑校acm算法训练课程 What a Ridiculous Election bfs预处理

题面描述 In country Light Tower, a presidential election is going on. There are two candidates, Mr. X1 and Mr. X2, and both of them are not like good persons. One is called a liar and the other is called...

菜鸡的水题之路 401

2016亚洲区域赛北京赛区K JiLi Number

Driver Ji likes the digit “1”. He has an accumulator which shows the sum of input number. He lists all of positive number no more than N and starts counting from one, two, three . . . Every time he co...

OtterVのrecorder 486

codeforces/contest/796/problem/E

E. Exam Cheating time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Zane and Zane’s crush have just decided to date! However, the girl is hav

creatorx的博客 1010

2017武汉大学校赛网络预选赛c题

无解时输出-1s而不是WTF数据可能有前导零Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 512 mebibytes A positive integer number n is written on a blackboard. It consists o

creatorx的博客 842

2017icpc北京网络赛c题(最大连续子段和)

时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Once upon a time, there was a little dog YK. One day, he went to an antique shop and was impressed by a beautiful picture. YK loved it very much. H

creatorx的博客 741

HDU6024(dp)

Building ShopsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 574 Accepted Submission(s): 221Problem Description HDU’s n classrooms are o

creatorx的博客 712
上一篇: hdu1269 运用tarjan算法求有向图中强连通分量数目
下一篇: 2016亚洲区域赛现场赛北京赛区f题
creatorx
博客等级 码龄10年 127粉丝 145原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值