C - A Great Alchemist
来源:互联网 发布:retrofit源码解析 编辑:程序博客网 时间:2024/05/16 05:43
C - A Great Alchemist
Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB
Problem
Carol is a great alchemist.
In her world, each metal has a name of 2N (N is an integer) letters long, which consists of uppercase alphabets.
Carol can create metal S3 from S1 and S2 alchemical when she can make the name of S3 by taking N letters each from S1 and S2 then rearranging them properly.
You are given 3 names of the metal S1, S2, S3. Determine wether Carol can create S3 from S1 and S2 or not.
Input
The input will be given in the following format from the Standard Input.
S1
S2
S3
On the first line, you will be given the name of the first metal material S1.
On the second line, you will be given the name of the second metal material S2.
On the third line, you will be given the name of the metal S3, which Carol wants to create.
It is guaranteed that 2≦|S1|≦105
Output
If Carol can create S3 from S1 and S2, output YES, if not, output NO in one line. Make sure to insert a line break at the end of the output.
Input Example 1
AABCCD
ABEDDA
EDDAAA
Output Example 1
YES
You can make EDDAAA by picking AAD from the first metal, and AED from the second metal.
Input Example 2
AAAAAB
CCCCCB
AAABCB
Output Example 2
NO
Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB
Problem
Carol is a great alchemist.
In her world, each metal has a name of 2N (N is an integer) letters long, which consists of uppercase alphabets.
Carol can create metal S3 from S1 and S2 alchemical when she can make the name of S3 by taking N letters each from S1 and S2 then rearranging them properly.
You are given 3 names of the metal S1, S2, S3. Determine wether Carol can create S3 from S1 and S2 or not.
Input
The input will be given in the following format from the Standard Input.
S1
S2
S3
On the first line, you will be given the name of the first metal material S1.
On the second line, you will be given the name of the second metal material S2.
On the third line, you will be given the name of the metal S3, which Carol wants to create.
Each character in the S1, S2, and S3 will be an uppercase English alphabet letter.
It is guaranteed that 2≦|S1|≦105
Output
If Carol can create S3 from S1 and S2, output YES, if not, output NO in one line. Make sure to insert a line break at the end of the output.
Input Example 1
AABCCD
ABEDDA
EDDAAA
Output Example 1
YES
You can make EDDAAA by picking AAD from the first metal, and AED from the second metal.
Input Example 2
AAAAAB
CCCCCB
AAABCB
Output Example 2
NO
To make AAABCB, you have to take at least four letters from the first material. So this can't be created alchemical.
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<cstring>int backtrack(char S3[],int n, int N);struct Point{char value;int flag;}point[200];int Sum = 0;int index[100], k = 0, Y_num = 0;int main(){char a[201], b[100],S3[100];gets(a);gets(b);gets(S3);strcat(a, b);int N = strlen(b)/2;int i, j;for (i = 0; i < 4 * N; i++){point[i].value = a[i];point[i].flag = 0;}backtrack(S3,0,N);if (Y_num != 0)printf("YES\n");else printf("NO\n");system("pause");return 0;} int backtrack(char S3[], int n, int N){int i, j = n;int left = 0, right = 0;if (n >= 2 * N){Sum++;for (k = 0;k<2*N; k++)//printf("index[k]=%d ", index[k]);//printf("\n");//printf("Sum = %d\n", Sum);if (Sum != 0){for (i = 0; i < 2 * N; i++){if (index[i] >= 0 && index[i] < 2 * N) left++;else right++;}//printf("right=%d,left=%d\n", right, left);if (left == right)Y_num++;//printf("YES\n");//else printf("NO\n");}//else printf("NO\n");return Y_num;}for (i = 0; i < 4 * N; i++){ index[n] = i;if (point[i].flag == 0 && point[i].value == S3[j]){point[i].flag = 1;//printf("index[k]=%d\n", index[k]);backtrack(S3, n+1, N);point[i].flag = 0;}}}
0 0
- C - A Great Alchemist
- A Great Alchemist
- A Great Alchemist
- atcoder之A Great Alchemist
- A great day
- A Great Writer
- Building A Great API
- TexturePacker--A great tool!
- A great spectacle
- A Great Start!
- A Great Man:Kalman
- 34. A great talker is a great liar.说大话者多慌言
- What makes a great team
- What Makes A Great Programmer?
- What Makes A Great Programmer?
- To be a great programmer
- codeforces:A. The Great Game
- It is a great start
- C语言Printf格式大全(各种%输出形式)
- 遍历安卓SDCard找出所有音乐、文本、图片的算法
- iOS开发 - Block块的使用(二)内存管理和特性
- Qt移动应用开发:实现跨平台的QML和OpenGL混合渲染
- ssh公钥无需输入密码访问其他机器
- C - A Great Alchemist
- 64部高智商电影
- http://movie.douban.com/doulist/14155603/
- Python切片操作
- Java解决编程猫狗鱼过河问题
- 个回复的回复的华国锋的郭德纲
- 安装DBDesigner4之路 for linux mint(ubuntu)
- 和规范化个凤凰股份合格的风格的师傅都是
- Customizing Navigation Bar and Status Bar in iOS 7 .