A. Specific Tastes of Andre
输出n个1
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define cl(x) x.clear()
#define all(x) x.begin() , x.end()
#define rep(i , x , n) for(int i = x ; i <= n ; i ++)
#define per(i , n , x) for(int i = n ; i >= x ; i --)
#define mem0(x) memset(x , 0 , sizeof(x))
#define mem_1(x) memset(x , -1 , sizeof(x))
#define mem_inf(x) memset(x , 0x3f , sizeof(x))
#define debug(x) cerr << #x << " = " << x << '\n'
#define ddebug(x , y) cerr << #x << " = " << x << " " << #y << " = " << y << '\n'
#define ios std::ios::sync_with_stdio(false) , cin.tie(0)
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef double db ;
const int mod = 998244353 ;
const int maxn = 2e5 + 10 ;
const int inf = 0x3f3f3f3f ;
const double eps = 1e-6 ;
int main()
{
ios ;
int T ;
cin >> T ;
while(T --)
{
int n ;
cin >> n ;
rep(i , 1 , n) cout << 1 << " \n"[i == n] ;
}
return 0 ;
}
B. Valerii Against Everyone
有两个相同的数就输出YES,否则输出NO
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define cl(x) x.clear()
#define all(x) x.begin() , x.end()
#define rep(i , x , n) for(int i = x ; i <= n ; i ++)
#define per(i , n , x) for(int i = n ; i >= x ; i --)
#define mem0(x) memset(x , 0 , sizeof(x))
#define mem_1(x) memset(x , -1 , sizeof(x))
#define mem_inf(x) memset(x , 0x3f , sizeof(x))
#define debug(x) cerr << #x << " = " << x << '\n'
#define ddebug(x , y) cerr << #x << " = " << x << " " << #y << " = " << y << '\n'
#define ios std::ios::sync_with_stdio(false) , cin.tie(0)
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef double db ;
const int mod = 998244353 ;
const int maxn = 2e5 + 10 ;
const int inf = 0x3f3f3f3f ;
const double eps = 1e-6 ;
int n ;
int b[maxn] ;
int main()
{
ios ;
int T ;
cin >> T ;
while(T --)
{
cin >> n ;
rep(i , 1 , n) cin >> b[i] ;
sort(b + 1 , b + n + 1) ;
bool flag = 0 ;
rep(i , 1 , n - 1) if(b[i] == b[i + 1]) flag = 1 ;
if(flag) cout << "YES\n" ;
else cout << "NO\n" ;
}
return 0 ;
}
C. Engineer Artem
黑白棋盘染色的思想,分一下奇偶即可。
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define cl(x) x.clear()
#define all(x) x.begin() , x.end()
#define rep(i , x , n) for(int i = x ; i <= n ; i ++)
#define per(i , n , x) for(int i = n ; i >= x ; i --)
#define mem0(x) memset(x , 0 , sizeof(x))
#define mem_1(x) memset(x , -1 , sizeof(x))
#define mem_inf(x) memset(x , 0x3f , sizeof(x))
#define debug(x) cerr << #x << " = " << x << '\n'
#define ddebug(x , y) cerr << #x << " = " << x << " " << #y << " = " << y << '\n'
#define ios std::ios::sync_with_stdio(false) , cin.tie(0)
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef double db ;
const int mod = 998244353 ;
const int maxn = 100 + 10 ;
const int inf = 0x3f3f3f3f ;
const double eps = 1e-6 ;
int a[maxn][maxn] ;
int main()
{
ios ;
int T ;
cin >> T ;
while(T --)
{
int n , m ;
cin >> n >> m ;
rep(i , 1 , n) rep(j , 1 , m) cin >> a[i][j] ;
rep(i , 1 , n) rep(j , 1 , m) a[i][j] += ((i + j) % 2 != a[i][j] % 2) ;
rep(i , 1 , n) rep(j , 1 , m) cout << a[i][j] << " \n"[j == m] ;
}
return 0 ;
}
D. Powerful Ksenia
首先有一个发现,。
假如n是奇数的时候,一定有解。
例如n=7。
第一步1 2 3
第二步3 4 5
第三步5 6 7
这样就会有a[1]=a[2],a[3]=a[4],a[5]=a[6]=a[7]
第四步1 2 7
第五步3 4 7
总共n-2步就解决了n是奇数的情况。
接着还有一个发现,就是三个数异或的操作不影响整个序列的异或值。
因此,如果n是偶数时,整个序列的异或值不是0,那么偶数情况就无解,否则依然用n-2步解决,因为相比于奇数情况多出的一个数正好与前n-1个数相同。
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define cl(x) x.clear()
#define all(x) x.begin() , x.end()
#define rep(i , x , n) for(int i = x ; i <= n ; i ++)
#define per(i , n , x) for(int i = n ; i >= x ; i --)
#define mem0(x) memset(x , 0 , sizeof(x))
#define mem_1(x) memset(x , -1 , sizeof(x))
#define mem_inf(x) memset(x , 0x3f , sizeof(x))
#define debug(x) cerr << #x << " = " << x << '\n'
#define ddebug(x , y) cerr << #x << " = " << x << " " << #y << " = " << y << '\n'
#define ios std::ios::sync_with_stdio(false) , cin.tie(0)
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef double db ;
const int mod = 998244353 ;
const int maxn = 2e5 + 10 ;
const int inf = 0x3f3f3f3f ;
const double eps = 1e-6 ;
int n ;
int a[maxn] ;
int main()
{
ios ;
cin >> n ;
rep(i , 1 , n) cin >> a[i] ;
int s = 0 ;
rep(i , 1 , n) s ^= a[i] ;
if(n % 2 == 0)
{
if(s != 0)
{
cout << "NO\n" ;
return 0 ;
}
n -- ;
}
cout << "YES\n" ;
cout << n - 2 << '\n' ;
for(int i = 1 ; i <= n - 2 ; i += 2) cout << i << ' ' << i + 1 << ' ' << i + 2 << '\n' ;
for(int i = 1 ; i <= n - 4 ; i += 2) cout << i << ' ' << i + 1 << ' ' << n << '\n' ;
return 0 ;
}
E. Yurii Can Do Everything
首先满足条件的答案很少,暴力找就行了。复杂度证明点这个,我就不班门弄斧了,出题人讲的很清楚了。
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define cl(x) x.clear()
#define all(x) x.begin() , x.end()
#define rep(i , x , n) for(int i = x ; i <= n ; i ++)
#define per(i , n , x) for(int i = n ; i >= x ; i --)
#define mem0(x) memset(x , 0 , sizeof(x))
#define mem_1(x) memset(x , -1 , sizeof(x))
#define mem_inf(x) memset(x , 0x3f , sizeof(x))
#define debug(x) cerr << #x << " = " << x << '\n'
#define ddebug(x , y) cerr << #x << " = " << x << " " << #y << " = " << y << '\n'
#define ios std::ios::sync_with_stdio(false) , cin.tie(0)
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef double db ;
const int mod = 998244353 ;
const int maxn = 2e5 + 10 ;
const int inf = 0x3f3f3f3f ;
const double eps = 1e-6 ;
int n ;
int a[maxn] ;
int ans = 0 ;
map<int , int> vis[maxn] ;
int main()
{
ios ;
cin >> n ;
rep(i , 1 , n) cin >> a[i] ;
rep(i , 1 , n)
{
int sum = a[i + 1] ;
int k = 0 ;
rep(j , 1 , 29) if((a[i] & (1 << j)) > 0) k = j ;
rep(j , i + 2 , n)
{
int s = (a[i] ^ a[j]) ;
if(s == sum) ans ++ , vis[i][j] = 1 ;
sum += a[j] ;
if(sum >= (1 << (k + 1))) break ;
}
}
reverse(a + 1 , a + n + 1) ;
rep(i , 1 , n)
{
int sum = a[i + 1] ;
int k = 0 ;
rep(j , 1 , 29) if((a[i] & (1 << j)) > 0) k = j ;
rep(j , i + 2 , n)
{
int s = (a[i] ^ a[j]) ;
if(s == sum && !vis[n - j + 1].count(n - i + 1)) ans ++ ;
sum += a[j] ;
if(sum >= (1 << (k + 1))) break ;
}
}
cout << ans << '\n' ;
return 0 ;
}
F. Olha and Igor
人类智慧题,做不来。
结论就是:随机420次询问,返回值出现次数最多的两个节点就是根节点的两个儿子。
然后固定u和v就是这两个儿子,再枚举n个节点作为w,返回的值和w相同的节点就是根节点。
具体证明点这个
基本想不到。虽然n+420已经写在题面上了。
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define cl(x) x.clear()
#define all(x) x.begin() , x.end()
#define rep(i , x , n) for(int i = x ; i <= n ; i ++)
#define per(i , n , x) for(int i = n ; i >= x ; i --)
#define mem0(x) memset(x , 0 , sizeof(x))
#define mem_1(x) memset(x , -1 , sizeof(x))
#define mem_inf(x) memset(x , 0x3f , sizeof(x))
#define debug(x) cerr << #x << " = " << x << '\n'
#define ddebug(x , y) cerr << #x << " = " << x << " " << #y << " = " << y << '\n'
#define ios std::ios::sync_with_stdio(false) , cin.tie(0)
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef double db ;
const int mod = 998244353 ;
const int maxn = 3e5 + 10 ;
const int inf = 0x3f3f3f3f ;
const double eps = 1e-6 ;
int h , n ;
struct node
{
int val , id ;
bool operator < (const node &s) const
{
return val > s.val ;
}
} cnt[maxn] ;
void ask()
{
int u , v , w ;
u = rand() % n + 1 ;
v = rand() % n + 1 ;
w = rand() % n + 1 ;
while(v == u || v == w || w == u)
{
v = rand() % n + 1 ;
w = rand() % n + 1 ;
}
printf("? %d %d %d\n" , u , v , w) ;
//cout << "? " << u << ' ' << v << ' ' << w << '\n' ;
fflush(stdout) ;
int x ;
scanf("%d" , &x) ;
//cin >> x ;
cnt[x].val ++ ;
}
int main()
{
//ios ;
srand(time(0)) ;
scanf("%d" , &h) ;
//cin >> h ;
n = (1 << h) - 1 ;
rep(i , 1 , n) cnt[i].id = i , cnt[i].val = 0 ;
rep(i , 1 , 420) ask() ;
sort(cnt + 1 , cnt + n + 1) ;
int ans = 1 ;
rep(i , 1 , n)
{
if(i == cnt[1].id || i == cnt[2].id) continue ;
printf("? %d %d %d\n" , cnt[1].id , cnt[2].id , i) ;
//cout << "? " << cnt[1].id << ' ' << cnt[2].id << ' ' << i << '\n' ;
fflush(stdout) ;
int x ;
scanf("%d" , &x) ;
//cin >> x ;
if(x == i) ans = x ;
}
printf("! %d\n" , ans) ;
//cout << "! " << ans << '\n' ;
return 0 ;
}