1032. Sharing 解析
来源:互联网 发布:票据市场知乎 编辑:程序博客网 时间:2024/06/05 02:53
有几个特殊情况:
1、开头就相同
2、不是以-1结尾
考虑到这两个就应该oK了。。
#include <iostream>#include <string>#include <vector>#define MAX 100010using namespace std;struct Node {char c;int next;};Node str[MAX];int main() {int p1, p2, N;cin >> p1 >> p2 >> N;int len1 = 0, len2 = 0;if (p1 == p2) {printf("%05d\n", p1);return 0;}int Add; for (int i = 0; i < N;i++) {scanf("%d", &Add); cin.get();scanf("%c %d", &str[Add].c, &str[Add].next);}int p = p1;while (p != -1) {#ifdef _DEBUGprintf("%05d %c %05d\n", p, str[p].c, str[p].next);#endifp = str[p].next;len1++;}p = p2;while (p != -1) {#ifdef _DEBUGprintf("%05d %c %05d\n", p, str[p].c, str[p].next);#endifp = str[p].next;len2++;}int i = p1,j = p2;int gap;if (len1 < len2) {gap = len2 - len1;while (gap) {j = str[j].next;gap--;}}else {gap = len1 - len2;while (gap) {i = str[i].next;gap--;}}bool tag = false;while (i != -1 && j != -1) {if (str[i].next == str[j].next) {if (str[j].next == -1)cout << "-1" << endl;elseprintf("%05d\n", str[i].next);tag = true;break;}else {i = str[i].next;j = str[j].next;}}if (!tag)cout << "-1" << endl;system("pause");return 0;}
0 0
- 1032. Sharing 解析
- 1032. Sharing
- 1032. Sharing
- 1032.Sharing
- 1032. Sharing
- 1032. Sharing
- 1032. Sharing
- 1032. Sharing
- 1032. Sharing (25)
- 1032. Sharing (25)-PAT
- 【PAT】1032. Sharing (25)
- 1032. Sharing (25)
- 1032. Sharing (25)
- PAT 1032. Sharing (25)
- PAT 1032. Sharing
- PAT 1032. Sharing (25)
- PAT 1032. Sharing (25)
- PAT:1032. Sharing (25)
- 深度学习中经常看到epoch、 iteration和batchsize
- Java中的集合框架
- C#编写ActiveX控件
- 使用FreeMarker生成静态HTML
- 《门徒》中的,高内聚、低耦合
- 1032. Sharing 解析
- Java - 文档注释(javadoc)
- nginx lua
- 蓝桥杯-第七届省赛javaA组-压缩变换
- Java多线程编程中Master-Worker模式的详解
- 根据类名创建ViewController
- spring的@transactional与mysql事务管理
- AngularJS的四大核心特性(二)
- batch normalization 正向传播与反向传播