Pots

Pots

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description

You are given two pots, having the volume of A and B liters respectively. The following operations can be performed:

FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap;
DROP(i) empty the pot i to the drain;
POUR(i,j) pour from pot i to pot j; after this operation either the pot j is full (and there may be some water left in the pot i), or the pot i is empty (and all its contents have been moved to the pot j).
Write a program to find the shortest possible sequence of these operations that will yield exactly C liters of water in one of the pots.
Input

On the first and only line are the numbers A, B, and C. These are all integers in the range from 1 to 100 and C≤max(A,B).
Output

The first line of the output must contain the length of the sequence of operations K. If the desired result can’t be achieved, the first and only line of the file must contain the word ‘impossible’.
Example Input

3 5 4
Example Output

6
Hint

FILL(2)
POUR(2,1)
DROP(1)
POUR(2,1)
FILL(2)
POUR(2,1)
Author

这道题是一道BFS的运用,有六种状态:
1.将A中的水倒满;
2.将B中的水倒满;
3.将A中的水倒空;
4.将B种的水倒空;
5.将A中的水倒入B中;
6.将B中的水倒入A中(考虑杯中是否已满);

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXN 121
int a, b, c;
int v[MAXN][MAXN];
struct node
{
    int x,y,step;
}que[MAXN*MAXN], p, q;
void bfs(int a, int b, int c)
{
    int front = 0, rear = 0;
    p.x = 0;
    p.y = 0;
    p.step = 0;
    que[rear++] = p;
    v[p.x][p.y] = 1;
    while(front<rear)
    {
        q = que[front++];
        if(q.x==c||q.y==c)
        {
            printf("%d\n", q.step);
            return ;
        }
        for(int i=0;i<6;i++)
        {
            if(i==0)//将B倒满
            {
                p.x = q.x;
                p.y = b;
            }
            if(i==1)//将A倒满
            {
                p.y = q.y;
                p.x = a;
            }
            if(i==2)//A倒空
            {
                p.x = 0;
                p.y = q.y;
            }
            if(i==3)//B倒空
            {
                p.y = 0;
                p.x = q.x;
            }
            if(i==4)//B倒入A
            {
                p.x = q.x + q.y;
                if(p.x>a)
                {
                    p.y = p.x - a;
                    p.x = a;
                }
                else
                    p.y = 0;
            }
            if(i==5)//A倒入B
            {
                p.y = q.y + q.x;
                if(p.y>b)
                {
                    p.x = p.y - b;
                    p.y = b;
                }
                else
                    p.x = 0;
            }
            if(v[p.x][p.y]==0)//判断是否可行
            {
                v[p.x][p.y]=1;
                p.step = q.step + 1;
                que[rear++] = p;
            }
        }
    }
    printf("impossible\n");
}
int main()
{
    while(~scanf("%d %d %d", &a, &b, &c))
    {
        memset(v, 0, sizeof(v));//清零
        bfs(a, b, c);
    }
    return 0;
}

You are given two pots, having the volume of A and B liters respectively. The following operations can be performed:

FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap;
DROP(i) empty the pot i to the drain;
POUR(i,j) pour from pot i to pot j; after this operation either the pot j is full (and there may be some water left in the pot i), or the pot i is empty (and all its contents have been moved to the pot j).
Write a program to find the shortest possible sequence of these operations that will yield exactly C liters of water in one of the pots.

Input
On the first and only line are the numbers A, B, and C. These are all integers in the range from 1 to 100 and C≤max(A,B).

Output
The first line of the output must contain the length of the sequence of operations K. The following K lines must each describe one operation. If there are several sequences of minimal length, output any one of them. If the desired result can’t be achieved, the first and only line of the file must contain the word ‘impossible’.

Sample Input
3 5 4
Sample Output
6
FILL(2)
POUR(2,1)
DROP(1)
POUR(2,1)
FILL(2)
POUR(2,1)

题目差不多,但是此题要记录所走的每一步~

#include <iostream>
#include <queue>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#define MAXN 123
using namespace std;
struct node
{
    int x,y,step;
    char operate[MAXN][MAXN];
}que[MAXN*MAXN], p, q, w;
int v[MAXN][MAXN];
int a, b, c;
void bfs()
{
    int front = 0, rear = 0;
    q.x = 0;
    q.y = 0;
    q.step = 0;
    que[rear++] = q;
    v[q.x][q.y] = 1;
    while(front<rear)
    {
        p = que[front++];
        if(p.x==c||p.y==c)
        {
            printf("%d\n", p.step);
            for(int i=1;i<=p.step;i++)
                printf("%s\n", p.operate[i]);
            return ;
        }
        if(p.x==0)
        {
            //FILL(1)
            q = p;
            q.x = a;
            q.y = p.y;
            q.step = p.step + 1;
            strcpy(q.operate[q.step], "FILL(1)");
            if(v[q.x][q.y]==0)
            {
                v[q.x][q.y] = 1;
                que[rear++] = q;
            }
        }
        else if(p.x!=0)
        {
            //DROP(1)
            q = p;
            q.x = 0;
            q.y = p.y;
            q.step = p.step + 1;
            strcpy(q.operate[q.step], "DROP(1)");
            if(v[q.x][q.y]==0)
            {
               v[q.x][q.y] = 1;
               que[rear++] = q;
            }
            //POUR(1, 2)
            if(p.y<b)
            {
                q = p;
                if(p.x+p.y>=b)
                {
                    q.x = p.x + p.y - b;
                    q.y = b;
                }
                else
                {
                    q.x = 0;
                    q.y = p.x + p.y;
                }
                q.step = p.step + 1;
                strcpy(q.operate[q.step], "POUR(1,2)");
                if(!v[q.x][q.y])
                {
                    v[q.x][q.y] = 1;
                    que[rear++] = q;
                }
            }
        }
        if(p.y==0)
        {
            //FILL(2)
            q = p;
            q.x = p.x;
            q.y = b;
            q.step = p.step + 1;
            strcpy(q.operate[q.step], "FILL(2)");
            if(v[q.x][q.y]==0)
            {
                v[q.x][q.y] = 1;
                que[rear++] = q;
            }
        }
        else if(p.y!=0)
        {
            //DROP(2)
            q = p;
            q.x = p.x;
            q.y = 0;
            q.step = p.step + 1;
            strcpy(q.operate[q.step], "DROP(2)");
            if(v[q.x][q.y]==0)
            {
               v[q.x][q.y] = 1;
               que[rear++] = q;
            }
            //POUR(2, 1)
            if(p.x<a)
            {
                q = p;
                if(p.x+p.y>=a)
                {
                    q.y = p.x + p.y - a;
                    q.x = a;
                }
                else
                {
                    q.y = 0;
                    q.x = p.x + p.y;
                }
                q.step = p.step + 1;
                strcpy(q.operate[q.step], "POUR(2,1)");
                if(!v[q.x][q.y])
                {
                    v[q.x][q.y] = 1;
                    que[rear++] = q;
                }
            }
        }
    }
    printf("impossible\n");
}
int main()
{
    scanf("%d %d %d", &a, &b, &c);
    memset(v, 0, sizeof(v));
    bfs();
    return 0;
}
<think>好的,用户想了解POTS电话系统的相关信息。首先,我需要回忆一下POTS的基本概念和结构。POTS是传统电话系统,属于模拟通信,使用双绞铜线连接。可能需要解释它的组成部分,比如本地环路、中心局交换机等。 然后,用户可能需要知道它的技术特点,比如频带范围、信令方式,以及供电方式。记得提到贝尔系统建立的规范和标准,比如300-3400Hz的语音频带。还有,供电方面,局端通过线路提供48V直流电,这对断电时保持通话很重要。 接下来,用户可能对优缺点感兴趣。优点比如可靠性高、兼容性好,缺点如带宽低、功能有限。这里需要对比现代VoIP,说明为什么POTS在紧急情况下更可靠。 应用场景方面,虽然逐渐被替代,但紧急电话、农村地区、传真等场景还在使用。需要举些例子,比如报警电话依赖POTS,因为断电时仍可用。 生成相关问题时,要考虑用户可能进一步想知道的内容,比如与VoIP的区别、工作原理细节、可靠性原因、现状如何,以及维护挑战。这些问题能帮助用户深入理解POTS的不同方面。 需要注意的是,用户可能对技术细节不熟悉,所以回答时要保持清晰,避免过于专业的术语,但也要准确。比如解释本地环路时,可以简单说明是用户到中心局的线路。同时,引用规范时要正确,比如ANSI T1.401标准。 最后,检查是否符合之前的系统级指令:行内公式用$...$,独立公式用$$...$$,但POTS相关内容可能不需要数学公式,不过如果有提到带宽范围,可以用$300-3400\text{Hz}$这样的格式。确保用中文回答,结构清晰,问题相关且能引导进一步学习。</think>### Plain Old Telephone Service (POTS) 电话系统介绍 Plain Old Telephone Service (POTS) 是传统模拟电话系统,自19世纪末发展至今,构成了现代通信网络的基础。其核心特征如下: #### 1. **系统架构** - **本地环路 (Local Loop)**:用户电话机通过双绞铜线连接到最近的**中心局 (Central Office, CO)**,这段线路称为"最后一公里",典型阻抗为$600\ \Omega$[^1]。 - **交换层级**:采用分级电路交换网络,包括本地交换局、长途交换中心等,使用SS7信令系统控制呼叫路由。 #### 2. **技术规范** - **频带范围**:语音信道带宽限制在$300-3400\ \text{Hz}$,由贝尔系统在20世纪40年代确立[^2] - **供电系统**:采用-48V直流幻象供电,通过线路为电话机提供工作电源,确保断电时仍可通话 - **信令方式**: - 脉冲拨号(旋转拨号盘)或DTMF双音多频 - 振铃电压为$90\ \text{VAC}$(20Hz) #### 3. **典型特性** | 特性 | 参数 | |-----------|------------------------| | 线路电压 | 挂机48V DC,摘机6-12V DC | | 环路电阻 | ≤1900Ω(ANSI T1.401标准)| | 传输损耗 | ≤8dB(用户端到交换局) | #### 4. **优缺点分析** - **优势**: - 高可靠性:无需外部电源即可工作 - 强兼容性:支持传真机、调制解调器等设备 - 低延迟:端到端模拟电路连接 - **局限**: - 带宽限制(仅3.1kHz) - 缺乏现代功能(如视频通话) - 维护成本高(铜线基础设施) #### 5. **应用场景** - **紧急通信**:911/110报警系统仍依赖POTS线路 - **农村地区**:缺乏宽带覆盖区域的通信保障 - **专用设备**:电梯紧急电话、金融交易终端等 ```mermaid graph LR A[用户电话机] -->|双绞铜线| B(配线架) B --> C{分线盒} C --> D[中心局交换机] D -->|中继线路| E[PSTN网络] ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值