NC217633. 反·反爬虫函数
描述
int calculatetta(char* a) { int b = 0; for (int c = 0; c < strlen(a); ++c) { b = (b + (c + 1) * (c + 2) * a[c]) % 1009; if (c % 3 == 0) ++b; if (c % 2 == 0) b *= 2; if (c > 0) b -= ((int) (a[c / 2] / 2)) * (b % 5); while (b < 0) b += 1009; while (b >= 1009) b -= 1009; } return b; }
def calculatetta(a: str): b = 0 for c in range(len(a)): b = (b + (c + 1) * (c + 2) * ord(a[c])) % 1009 if c % 3 == 0: b = b + 1 if c % 2 == 0: b = b * 2 if c > 0: b = b - (ord(a[c // 2]) // 2) * (b % 5) while b < 0: b = b + 1009 while b >= 1009: b = b - 1009 return b
public static int calculatetta(String a) { int b = 0; for (int c = 0; c < a.length(); ++c) { b = (b + (c + 1) * (c + 2) * ((int) a.charAt(c))) % 1009; if (c % 3 == 0) ++b; if (c % 2 == 0) b *= 2; if (c > 0) b -= (((int) a.charAt(c / 2)) / 2) * (b % 5); while (b < 0) b += 1009; while (b >= 1009) b -= 1009; } return b; }
输入描述
首先输入一个正整数,表示案例组数,每组案例输入一个正整数,表示的值
输出描述
对于每组样例输出一个长度为的字符串,表示所对应的字符串,有多个答案输出任意即可,若无解输出。注意,你输出的字符串,只能含有大写字母、小写字母、数字中的一种或几种(不能输出特殊字符)。
示例1
输入:
2 766 285
输出:
CFmFhwJa CFE3wu8l
说明:
pypy3 解法, 执行用时: 409ms, 内存消耗: 39180K, 提交时间: 2021-06-18 20:28:54
import random import string def gen(n: int) -> str: return ''.join(random.choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for _ in range(n)) def calculatetta(a: str): b = 0 for c in range(len(a)): b = (b + (c + 1) * (c + 2) * ord(a[c])) % 1009 if c % 3 == 0: b = b + 1 if c % 2 == 0: b = b * 2 if c > 0: b = b - (ord(a[c // 2]) // 2) * (b % 5) while b < 0: b = b + 1009 while b >= 1009: b = b - 1009 return b res = [None for _ in range(1009)] for i in range(30000): s = gen(8) res[calculatetta(s)] = s T = int(input()) for cas in range(T): n = int(input()) if n >= 1009: print('-1') else: print(res[n])
C++ 解法, 执行用时: 16ms, 内存消耗: 504K, 提交时间: 2021-06-10 18:14:04
#include<bits/stdc++.h> using namespace std; #define N 1005 #define For(i,x,y)for(i=x;i<=(y);i++) int vis[N]; int a[N],b[N],c[N]; int main() { int n,i,x,y; x=y=0; cin>>n; For(i,1,n)cin>>a[i]; For(i,1,n) { cin>>b[i]; if(a[i]!=b[i])if(x)y=i; else x=i; } For(i,1,n) if(i!=x&&i!=y)c[i]=a[i],vis[a[i]]=1; if(!y) For(i,1,n) if(!vis[i]) { c[x]=i; break; } else;else { if(!vis[a[x]]&&!vis[b[y]])c[x]=a[x],c[y]=b[y]; else c[y]=a[y],c[x]=b[x]; } For(i,1,n)cout<<c[i]<<' '; return 0; }