div.4只写部分题解了,都比较基础,数学偏多一点,几乎没有算法,有不懂的欢迎评论区提问!
A. My First Sorting Problem
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}ll a[maxn] , n , m , t ;void solve(){n = read() ;m = read() ;cout << min(n , m) << " " << max(n , m) << endl ;
}
int main(){t = read() ;while(t --){solve() ;}return 0 ;
}
B. Different String
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}ll a[maxn] , n , m , t ;
char s[maxn] ;
void solve(){scanf("%s" , s + 1) ;ll len = strlen(s + 1) ;map < int , int > mp ;for(int i = 1 ; i <= len ; i ++){mp[s[i] - 'a' + 1] ++ ;}for(auto it : mp){if(it.second == len){cout << "NO\n" ;return ;}}cout << "YES\n" ;for(int i = 2 ; i <= len ; i ++){cout << s[i] ;}cout << s[1] << endl ;
}
int main(){t = read() ;while(t --){solve() ;}return 0 ;
}
C. Clock and Strings
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}ll a[maxn] , n , m , t ;
char s[maxn] ;
ll A , B , C , D ;
void solve(){A = read() ;B = read() ;C = read() ;D = read() ;if(A > B){swap(A , B) ;}if(((C < A || C > B) && (D < A || D > B)) || (C <= B && C >= A && D <= B && D >= A) ){cout << "NO\n" ;}else{cout << "YES\n" ;}
}
int main(){t = read() ;while(t --){solve() ;}return 0 ;
}
D. Binary Cut
可以发现,能优化的只有0011这种情况,可以将两块合成一块。
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}ll a[maxn] , n , m , t ;
char s[maxn] ;
void solve(){scanf("%s" , s + 1) ;int len = strlen(s + 1) ;bool f = 0 ;ll sum = 0 ;for(int i = 1 ; i <= len ;){if(s[i] == '0'){sum ++ ;ll rt = i ;for(int j = i ; j <= len ; j ++){if(j == len && s[j] == '0'){rt = len + 1 ;break ;}if(s[j] == '0')continue ;else{rt = j ;break ;}}i = rt ;if(f == 0){f = 1 ;ll Rt = rt ;for(int j = rt ; j <= len ; j ++){if(j == len && s[j] == '1'){Rt = len + 1 ;break ;}if(s[j] == '1')continue ;else{Rt = j ;break ;}}i = Rt ;}continue ;}if(s[i] == '1'){ll rt = i ;for(int j = i ; j <= len ; j ++){if(j == len && s[j] == '1'){rt = len + 1 ;break ;}if(s[j] == '1')continue ;else{rt = j ;break ;}}i = rt ;sum ++ ;}}cout << sum << endl ;
}
int main(){t = read() ;while(t --){solve() ;}return 0 ;
}
E. Find the Car
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}ll t , n , k , q ;
double a[maxn] , b[maxn] ;
double c[maxn] ;
char s[maxn] ;
void solve(){n = read() ;k = read() ;q = read() ;for(int i = 1 ; i <= k ; i ++){cin >> a[i] ;}for(int i = 1 ; i <= k ; i ++){cin >> b[i] ;}for(int i = 1 ; i <= k ; i ++){c[i] = (double)(a[i] - a[i - 1]) / (double)(b[i] - b[i - 1]) * 1.0 ;}for(int i = 1 ; i <= q ; i ++){double u ;cin >> u ;ll l = 1 , r = k , ans = -1 ;while(l <= r){ll mid = (l + r) / 2 ;if(a[mid] <= u){ans = mid ;l = mid + 1 ;}else{r = mid - 1 ;}}if(ans == -1){ll dd = (ll)(u / c[1]) ;cout << dd << endl ;}else{ll rt = ans + 1 ;if(u == a[ans]){ cout << b[ans] << endl ;continue ;}ll dd = (ll)floor((u - a[ans]) / c[rt]) ;cout << (ll)dd + (ll)(b[ans]) << endl ;}}
}
int main(){t = read() ;while(t --){solve() ;}return 0 ;
}
F. Circle Perimeter
看数据范围过不了,所以就想用复杂度更低的方法,可以发现可以枚举一层,然后找到数据范围,用二分求出中间有多少数字,然后统计答案即可。复杂度。
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}ll a[maxn] , n , m , t ;
char s[maxn] ;
void solve(){n = read() ;ll l = n * n ;ll r = (n + 1) * (n + 1) ;ll anss = 0 ;for(ll i = 1 ; i <= n ; i ++){ll L = l - i * i ;ll R = (r - 1) - i * i ;ll l = 0 , r = n , ans = -1 ;while(l <= r){ll mid = (l + r) / 2 ;if(mid * mid > L){r = mid - 1 ;}else{ans = mid ;l = mid + 1 ;}}if(ans * ans != L){ans ++ ;}l = 0 , r = n ;ll Ans = -1 ;while(l <= r){ll mid = (l + r) / 2 ;if(mid * mid <= R){l = mid + 1 ;Ans = mid ;}else{r = mid - 1 ;}}anss += (Ans - ans + 1) * 4 ;}cout << anss << endl ;
}
int main(){t = read() ;while(t --){solve() ;}return 0 ;
}
G. XOUR
因为,所以只会和最后两位有关系,如果说其他位有不同,那必然会大于4,所以用map存一下,映射顺序输出即可。
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {ll x = 0, f = 1 ;char c = getchar() ;while (c > '9' || c < '0') {if (c == '-')f = -1 ;c = getchar() ;}while (c >= '0' && c <= '9') {x = x * 10 + c - '0' ;c = getchar() ;}return x * f ;
}ll a[maxn] , n , m , t ;
char s[maxn] ;
void solve(){n = read() ;for(int i = 1 ; i <= n ; i ++){a[i] = read() ;}map < ll , priority_queue < ll > > mp ;for(int i = 1 ; i <= n ; i ++){mp[a[i] >> 2].push(-a[i]) ;}for(int i = 1 ; i <= n ; i ++){cout << -mp[a[i] >> 2].top() << " " ;mp[a[i] >> 2].pop() ;}cout << endl ;
}
int main(){t = read() ;while(t --){solve() ;}return 0 ;
}