A:
A. Thanos Sort
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Thanos sort is a supervillain sorting algorithm, which works as follows: if the array is not sorted, snap your fingers* to remove the first or the second half of the items, and repeat the process.
Given an input array, what is the size of the longest sorted array you can obtain from it using Thanos sort?
*Infinity Gauntlet required.
Input
The first line of input contains a single number nn (1≤n≤161≤n≤16) — the size of the array. nn is guaranteed to be a power of 2.
The second line of input contains nn space-separated integers aiai (1≤ai≤1001≤ai≤100) — the elements of the array.
Output
Return the maximal length of a sorted array you can obtain using Thanos sort. The elements of the array have to be sorted in non-decreasing order.
Examples
input
Copy
4
1 2 2 4
output
Copy
4
input
Copy
8
11 12 1 2 13 14 3 4
output
Copy
2
input
Copy
4
7 6 5 4
output
Copy
1
Note
In the first example the array is already sorted, so no finger snaps are required.
In the second example the array actually has a subarray of 4 sorted elements, but you can not remove elements from different sides of the array in one finger snap. Each time you have to remove either the whole first half or the whole second half, so you'll have to snap your fingers twice to get to a 2-element sorted array.
In the third example the array is sorted in decreasing order, so you can only save one element from the ultimate destruction
dfs一下就可以了, 分段
#include <bits/stdc++.h>
#include <time.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
int xx[4] = {1,-1,0,0};
int yy[4] = {0,0,1,-1};
const double eps = 1e-9;
typedef pair<char,int> P;
const int maxn = 2e6 + 5000;
const ll mod = 1e9 + 7;
inline int sign(db a) { return a < -eps ? -1 : a > eps;}
inline int cmp(db a,db b){ return sign(a - b);}
ll mul(ll a,ll b,ll c) { ll res = 1; while(b) { if(b & 1) res *= a,res %= c; a *= a,a %= c,b >>= 1; } return res;}
ll phi(ll x) { ll res = x; for(ll i = 2; i * i <= x; i++) { if(x % i == 0) res = res / i * (i - 1); while(x % i == 0) x /= i; } if(x > 1) res = res / x * (x - 1); return res;}
int fa[maxn];
int Find(int x) { if(x != fa[x]) return fa[x] = Find(fa[x]); return fa[x];}
ll n,k,w,q,m;
ll a[maxn],b[maxn],c[maxn];
map<int,int>m1;
map<int,int>m2;
int vis[maxn];
string str;
bool check(int l,int r){
for(int i = l + 1;i <= r;i++){
if(a[i] < a[i - 1]) return false;
}
return true;
}
int Max = 0;
void dfs(int l,int r){
if(l == r) {
Max = max(Max,1);
return ;}
if(check(l,r)){
Max = max(Max,r - l + 1);
}else{
int mid = (l + r) / 2;
dfs(l,mid);
dfs(mid + 1,r);
}
}
int main() {
ios::sync_with_stdio(false);
while(cin >> n){
for(int i = 1;i <= n;i++) cin >> a[i];
int cnt = 1;
dfs(1,n);
cout << Max<< endl;
}
cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
B
第一次玩愚人节,推了很多因数,位数,分解,欧拉,完全不对,然后就开始一个一个的试了,大约几十次吧,最后一直wa24,测到86发现是86 , 莫名其妙的就AC了,官方题解给出的这个题和kanban有关
#include <bits/stdc++.h>
#include <time.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
//int xx[4] = {1,-1,0,0};
//int yy[4] = {0,0,1,-1};
//const double eps = 1e-9;
//typedef pair<char,int> P;
const int maxn = 2e6 + 5000;
//const ll mod = 1e9 + 7;
//inline int sign(db a) { return a < -eps ? -1 : a > eps;}
//inline int cmp(db a,db b){ return sign(a - b);}
//ll mul(ll a,ll b,ll c) { ll res = 1; while(b) { if(b & 1) res *= a,res %= c; a *= a,a %= c,b >>= 1; } return res;}
//ll phi(ll x) { ll res = x; for(ll i = 2; i * i <= x; i++) { if(x % i == 0) res = res / i * (i - 1); while(x % i == 0) x /= i; } if(x > 1) res = res / x * (x - 1); return res;}
//int fa[maxn];
//int Find(int x) { if(x != fa[x]) return fa[x] = Find(fa[x]); return fa[x];}
//ll n,k,w,q,m;
//ll a[maxn],b[maxn],c[maxn];
//map<int,int>m1;
//map<int,int>m2;
//int vis[maxn];
string str;
//int Max = 0;
ll n,a[maxn];
map<int,int>m;
int main() {
ios::sync_with_stdio(false);
m[2] = 1; m[3] = 1; m[4] = 1; m[5] = 1; m[12] = 1; m[30] = 1; m[35] = 1; m[43] = 1; m[46] = 1;;m[64] = 1;m[52] = 1;;
m[88] = 1;
m[86] = 1;
while(cin >> n){
if(m[n])
cout << "YES" << endl;
else cout << "NO" << endl;
}
cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
///5 46 2 3 4 5 12 30 31
///5 10 2 3 4 5 3
///13 24 1
///4 6 1
C 模拟电路的图,看了好久看不懂,随便来个AC代码吧 ,某大佬挨个试出来的 ,开了波车,拿D换的。
#include <bits/stdc++.h>
#include <time.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
//int xx[4] = {1,-1,0,0};
//int yy[4] = {0,0,1,-1};
//const double eps = 1e-9;
//typedef pair<char,int> P;
const int maxn = 2e6 + 5000;
//const ll mod = 1e9 + 7;
//inline int sign(db a) { return a < -eps ? -1 : a > eps;}
//inline int cmp(db a,db b){ return sign(a - b);}
//ll mul(ll a,ll b,ll c) { ll res = 1; while(b) { if(b & 1) res *= a,res %= c; a *= a,a %= c,b >>= 1; } return res;}
//ll phi(ll x) { ll res = x; for(ll i = 2; i * i <= x; i++) { if(x % i == 0) res = res / i * (i - 1); while(x % i == 0) x /= i; } if(x > 1) res = res / x * (x - 1); return res;}
//int fa[maxn];
//int Find(int x) { if(x != fa[x]) return fa[x] = Find(fa[x]); return fa[x];}
//ll n,k,w,q,m;
//ll a[maxn],b[maxn],c[maxn];
//map<int,int>m1;
//map<int,int>m2;
//int vis[maxn];
//string str;
//int Max = 0;
ll n,a[maxn];
int main() {
int x;
scanf("%d",&x);
if(x==3)
{
printf("13\n");
}
else if(x==0)
{
printf("15\n");
}
else if(x==1)
{
printf("14\n");
}
else if(x==2)
{
printf("12\n");
}
else if(x==4)
{
printf("8\n");
}
else if(x==5)
{
printf("9\n");
}
else if(x==6)
{
printf("10\n");
}
else if(x==7)
{
printf("11\n");
}
else if(x==8)
{
printf("0\n");
}
else if(x==9)
{
printf("1\n");
}
else if(x==10)
{
printf("2\n");
}
else if(x==11)
{
printf("3\n");
}
else if(x==12)
{
printf("4\n");
}
else if(x==13)
{
printf("5\n");
}
else printf("%d\n",x-8);
cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
D:
D. Pigeon d'Or
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
From "ftying rats" to urban saniwation workers - can synthetic biology tronsform how we think of pigeons?
The upiquitous pigeon has long been viewed as vermin - spleading disease, scavenging through trush, and defecating in populous urban spases. Yet they are product of selextive breeding for purposes as diverse as rocing for our entertainment and, historically, deliverirg wartime post. Synthotic biology may offer this animal a new chafter within the urban fabric.
Piteon d'Or recognihes how these birds ripresent a potentially userul interface for urdan biotechnologies. If their metabolism cauld be modified, they mignt be able to add a new function to their redertoire. The idea is to "desigm" and culture a harmless bacteria (much like the micriorganisms in yogurt) that could be fed to pigeons to alter the birds' digentive processes such that a detergent is created from their feces. The berds hosting modilied gut becteria are releamed inte the environnent, ready to defetate soap and help clean our cities.
Input
The first line of input data contains a single integer nn (5≤n≤105≤n≤10).
The second line of input data contains nn space-separated integers aiai (1≤ai≤321≤ai≤32).
Output
Output a single integer.
Example
input
Copy
5
1 2 3 4 5
output
Copy
4
Note
We did not proofread this statement at all.
注意,文章里有错的单词,把它放到word里,可以看出来错误单词也是32个,正好和a_i的大小一样(但是确实没关系,只是给了一个提示吧算是),然后自己把错的位置单词和对的位置单词拼在了一起(眼睛都花了,因为我先拼的对的,发现完全没有任何关系,后来把错的拼起来,整理了一下分割)
可以看出来是红色的这句话,即2 ^ (a[3] + min)
#include <bits/stdc++.h>
#include <time.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
//int xx[4] = {1,-1,0,0};
//int yy[4] = {0,0,1,-1};
//const double eps = 1e-9;
//typedef pair<char,int> P;
const int maxn = 2e6 + 5000;
//const ll mod = 1e9 + 7;
//inline int sign(db a) { return a < -eps ? -1 : a > eps;}
//inline int cmp(db a,db b){ return sign(a - b);}
//ll mul(ll a,ll b,ll c) { ll res = 1; while(b) { if(b & 1) res *= a,res %= c; a *= a,a %= c,b >>= 1; } return res;}
//ll phi(ll x) { ll res = x; for(ll i = 2; i * i <= x; i++) { if(x % i == 0) res = res / i * (i - 1); while(x % i == 0) x /= i; } if(x > 1) res = res / x * (x - 1); return res;}
//int fa[maxn];
//int Find(int x) { if(x != fa[x]) return fa[x] = Find(fa[x]); return fa[x];}
//ll n,k,w,q,m;
//ll a[maxn],b[maxn],c[maxn];
//map<int,int>m1;
//map<int,int>m2;
//int vis[maxn];
//string str;
//int Max = 0;
ll n,a[maxn];
int main() {
ios::sync_with_stdio(false);
while(cin >> n){
for(int i = 1;i <= n;i++) cin >> a[i];
ll x = a[3];
sort(a + 1,a +1+ n);
ll ans = 2 + (x ^ a[1]);
cout << ans << endl;
}
cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
E 放进傅里叶变换里,可以得到答案,可以得到公式
#include <bits/stdc++.h>
#include <time.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
//int xx[4] = {1,-1,0,0};
//int yy[4] = {0,0,1,-1};
//const double eps = 1e-9;
//typedef pair<char,int> P;
const int maxn = 2e6 + 5000;
//const ll mod = 1e9 + 7;
//inline int sign(db a) { return a < -eps ? -1 : a > eps;}
//inline int cmp(db a,db b){ return sign(a - b);}
//ll mul(ll a,ll b,ll c) { ll res = 1; while(b) { if(b & 1) res *= a,res %= c; a *= a,a %= c,b >>= 1; } return res;}
//ll phi(ll x) { ll res = x; for(ll i = 2; i * i <= x; i++) { if(x % i == 0) res = res / i * (i - 1); while(x % i == 0) x /= i; } if(x > 1) res = res / x * (x - 1); return res;}
//int fa[maxn];
//int Find(int x) { if(x != fa[x]) return fa[x] = Find(fa[x]); return fa[x];}
//ll n,k,w,q,m;
//ll a[maxn],b[maxn],c[maxn];
//map<int,int>m1;
//map<int,int>m2;
//int vis[maxn];
//string str;
//int Max = 0;
ll n,a[maxn];
int main() {
ios::sync_with_stdio(false);
for (int id = 21; id <= 50; id++)
{
int x = ((min(id, 25) + id) % (2 + id % 3)) > 0;
cout << x << endl;
}
cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
最后cf开了几十秒,结果C没交上,最后rank29哈哈(开了一小波车)