ACwing 第69场周赛
T1:
题意:A位于x,速度为a, B位于y,速度为b,(x < y),相向而行,是否在某个整数刻AB相遇
点击查看代码
#include<bits/stdc++.h>
using i64 = long long;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int tt = 1; std::cin >> tt;
while(tt--){
int x, y; std::cin >> x >> y;
int a, b; std::cin >> a >> b;
if((y - x) % (a + b)){
std::cout << -1 << '\n';
}else{
std::cout << (y - x) / (a + b) << '\n';
}
}
return 0;
}
T2:
题意:n个位置,k个位置已经被探索,问最少探索几个可以使得必定探索到导弹
只有已探索位置之间大于b才有可能存在导弹,且最多存在(len / b)个导弹,则先计算最多可能存在多少导弹,然后探索位置,使得探索后至多存在a - 1个位置,这样就可以保证一定探索到了导弹
点击查看代码
#include<bits/stdc++.h>
using i64 = long long;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int tt = 1; //std::cin >> tt;
while(tt--){
int n, a, b, ks;
std::cin >> n >> a >> b >> ks;
std::string s;
std::cin >> s;
std::vector<int> x(n);
for(int i = 0; i < n; ++i){
x[i] = s[i] - '0';
}
std::vector<std::pair<int, int>> q;
int res = n;
for(int i = 0; i < n; ++i){
int r = i;
if(x[i] == 1){
continue;
}
while(r + 1 < n && x[r + 1] == 0){
++r;
}
if(r - i + 1 >= b){
q.push_back({i, r});
}
i = r;
}
int k = 0;
for(auto xx : q){
k += (xx.second - xx.first + 1) / b;
}
k -= (a - 1);
std::vector<int> qq; int now = 0;
for(auto xx : q){
int kk = (xx.second - xx.first + 1) / b;
for(int i = 1; i <= kk; ++i){
int p = xx.first + i * b;
qq.push_back(p);
now += 1;
if(now == k){
break;
}
}
if(now == k){
break;
}
}
std::cout << now << '\n';
for(auto x : qq){
std::cout << x << ' ';
}
}
return 0;
}
T3:$$a \oplus x = a - x$$, 求有几个解
首先可以断定必定有x <= a, 然后打表,有规律,即1 << (__builtin__popcount(a))
点击查看代码
#include<bits/stdc++.h>
using i64 = long long;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int tt = 1; std::cin >> tt;
while(tt--){
int a; std::cin >> a;
std::cout << (1 << (__builtin_popcount(a))) << '\n';
}
return 0;
}
浙公网安备 33010602011771号