HDU 4357 String change 规律题

题意:

给定a串b串,问能否把a变成b串

方法:任选a的2个字母,ascil+=1 然后交换位置,可以操作任意多次。

3个及3个以上一定可以T^T

2个就暴力判一下

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 66;
char a[N], b[N];
bool check() {
	int n = 60;
	while(n -- > 0) {
		swap(a[0], a[1]);
		a[0] ++;
		a[1] ++;
		if(a[0] > 'z') a[0] = 'a';
		if(a[1] > 'z') a[1] = 'a';

		if(a[0] == b[0] && a[1] == b[1]) return true;
	}
	return false;
}

int main() {
	int T, cas = 0;
	scanf("%d", &T);
	while(T-- > 0) {
		scanf("%s%s", a, b);
		int n = strlen(a);
		bool ok = 0;
		if(n == 2) {
			if(check()) ok = 1;
			else ok = 0;
		} else {
			int s1 = 0, s2 = 0;
			for(int i = 0; i < n; i ++) {
				s1 += a[i] - 'a';
				s2 += b[i] - 'a';
			}
			if((s1+s2)&1) ok = 0;
			else ok = 1;
		}
		if(ok) printf("Case #%d: YES\n", ++cas);
		else printf("Case #%d: NO\n", ++cas);
	}
	return 0;
}
时间: 2024-08-04 23:13:59

HDU 4357 String change 规律题的相关文章

HDU 4357——String change——————【规律题】

String change Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1116    Accepted Submission(s): 494 Problem Description In this problem you will receive two strings S1 and S2 that contain only low

HDU 4937 Lucky Number 规律题_(:зゝ∠)_

把所有合法的进制打出来会发现合法的进制都是在 n/3 n/4 n/5的边上 然后暴力边上的进制数.. #include <cstdio> #include <set> typedef long long ll; bool ok(ll x, ll y) { ll v; while (x > 0) { v = x % y; if (v != 3 && v != 4 && v != 5 && v != 6) return false;

HDU 4952 Number Transformation 规律题

打表可以知道到后面增量都一样了,, 推论就是  i 和 i+1 互质 #include <cstdio> #include <algorithm> #include <cstring> #include <iostream> using namespace std; typedef long long ll; const ll mx = 120000; int main() { int cas = 0; ll x, k, y, dis, i; while (

HDU 5422-Rikka with Graph(规律题)

题目地址:HDU 5422 题意: 思路: 如果连上1-n的边,最短距离就是1.所以所有情况下最短距离都是1.考虑方案数,如果本来没有1-n的边,那么只能连1-n,方案数为1.否则怎么连都可以,方案数是n*(n-1)/2. int main() { int n,m; int x,y; while(~scanf("%d %d",&n,&m)) { int flag = 0; for(int i=0; i<m; i++) { scanf("%d %d&quo

HDU 4279 Number 规律题

题意: 定义函数F(x) : 区间[1,x]上的y是满足:GCD(x,y)>1 && x%y>0的 y的个数. 问:对于任意区间[l,r] 上的F(l···r) 有几个函数值是奇数的. 打表找规律. 打的是[1,x]区间的结果 把所有结果不相同的值打出来(因为结果是递增的,所以只观察不相同的结果) 发现:ans = x/2-2 || x/2-1 再把所有结果不同 && x/2-1的值打出来 发现 sqrt(x) &1 == 1 得到:ans = x/2-

HDU 4148 Length of S(n)(规律题)

Problem Description http://acm.hdu.edu.cn/showproblem.php?pid=4148 A number sequence is defined as following: S(1)=1, S(2)=11, S(3)=21, S(4)=1211, S(5)=111221, S(6)=312211, -- Now, we need you to calculate the length of S(n). Input The input consists

HDU 4940 Destroy Transportation system 规律题

答案只有2种情况,所以ans = rand()%2; if(ans)puts("happy") else puts("unhappy"); == 想过无源汇的网络流,还是比较麻烦的,然后没往下想... 设s点集有一些点, 多加一个点一定是y增加比较快_(:зゝ∠)_ 然后设s点集只有一个点 #include <cstdio> #include <map> #include <set> #include <algorithm&

HDU 4893 线段树裸题

Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2512    Accepted Submission(s): 751 Problem Description Recently, Doge got a funny birthday present from his new friend, Pro

hdu 2053 Switch Game 水题一枚,鉴定完毕

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10200    Accepted Submission(s): 6175 Problem Description There are many lamps in a line. All of them are off at first. A series of op