闲得无聊打打比赛,大多数都是枚举和小贪心,很好想,只附上代码。
A-分饼干 I
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 , m , xx , yy , x2 , y2 , a[maxn] , b[maxn] , c[maxn] ;
char s[maxn] , S[maxn] , ss[maxn] ;
ll f[maxn][3] ;
int main(){
a[1] = read() ;
a[2] = read() ;
a[3] = read() ;
sort(a + 1 , a + 4 , greater <>()) ;
ll Ans = INT_MAX ;
ll sum = a[1] + a[2] + a[3] ;
ll l , r ;
for(int i = 1 ; i <= 3 ; i ++){
for(int j = 1 ; j + i - 1 <= 3 ; j ++){
ll res = 0 , ans = 0 ;
for(int k = j ; k <= j + i - 1 ; k ++){
res += a[k] ;
}
ans = sum - res ;
if(res > ans){
if(res - ans < Ans){
Ans = res - ans ;
l = res ;
r = ans ;
}
}
}
}
cout << l << " " << r << endl ;
return 0 ;
}
B-分饼干 II
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , c[maxn] ;
char s[maxn] , S[maxn] , ss[maxn] ;
ll f[maxn][3] ;
void solve(){
n = read() ;
k = read() ;
if(n >= (((1ll + k) * k) / 2ll)){
cout << "Yes\n" ;
}
else{
cout << "No\n" ;
}
}
int main(){
t = read() ;
while(t --){
solve() ;
}
return 0 ;
}
C-跳房子
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , c[maxn] ;
char s[maxn] , S[maxn] , ss[maxn] ;
ll f[maxn][3] ;
int main(){
n = read() ;
for(int i = 1 ; i <= n ; i ++){
a[i] = read() ;
}
ll cnt = 0 , rt = 1 ;
while(1){
if(rt >= n){
break ;
}
cnt ++ ;
rt = rt + a[rt] ;
}
if(rt == n){
cout << "Yes\n" ;
cout << cnt << endl ;
}
else{
cout << "No\n" ;
cout << cnt << endl ;
}
return 0 ;
}
D-区间函数最小值
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 , B , C , D , E , F , G , P , l1 , r1 , l2 , r2 ;
ll t , n , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , c[maxn] ;
char s[maxn] , S[maxn] , ss[maxn] ;
ll f[maxn][3] ;
int main(){
A = read() ;
B = read() ;
C = read() ;
D = read() ;
E = read() ;
F = read() ;
G = read() ;
P = read() ;
l1 = read() ;
r1 = read() ;
l2 = read() ;
r2 = read() ;
ll ans = -INT_MAX ;
for(ll i = l1 ; i <= r1 ; i ++){
for(ll j = l2 ; j <= r2 ; j ++){
ll res = ((((((A * i) % P * i) % P) * i) % P) + (((((B * j) % P )* j) % P) * j) % P ) ;
res %= P ;
res = ((res + ((((((C * i) % P) * i) % P) * j ) % P)) % P + ((((((D * i) % P) * j) % P) * j) % P)) ;
res %= P ;
res = (res + ((((E * i) % P) * j) % P)) % P + ((F * i) % P );
res %= P ;
res = (res + ((G * j) % P)) % P ;
ans = max(ans , res) ;
}
}
cout << ans <<endl ;
return 0 ;
}
E-小跳蛙
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 , B , C , D , E , F , G , P , l1 , r1 , l2 , r2 ;
ll t , n , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , c[maxn] ;
char s[maxn] , S[maxn] , ss[maxn] ;
ll f[maxn][3] ;
int main(){
n = read() ;
for(int i = 1 ; i <= n ; i ++){
a[i] = read() ;
}
map < ll , ll > mp ;
for(int i = 1 ; i <= n ; i ++){
mp[a[i]] = i ;
}
for(int i = 1 ; i <= n - 1 ; i ++){
b[mp[i - 1]] = i ;
}
b[mp[n - 1]] = 0 ;
for(int i = 1 ; i <= n ; i ++){
cout << b[i] << " " ;
}
cout << endl ;
return 0 ;
}
F-图像变换
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 , B , C , D , E , F , G , P , l1 , r1 , l2 , r2 ;
ll t , n , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , c[maxn] ;
char s[200][1050] , S[200][1050] ;
ll f[maxn][3] ;
int main(){
n = read() ;
m = read() ;
k = read() ;
for(int i = 1 ; i <= n ; i ++){
for(int j = 1 ; j <= m ; j ++){
cin >> s[i][j] ;
}
}
for(int i = 1 ; i <= n ; i ++){
int cnt = 0 ;
for(int j = 1 ; j <= m ; j ++){
for(int w = 1 ; w <= k ; w ++){
S[i][++ cnt] = s[i][j] ;
}
}
}
for(int i = 1 ; i <= n ; i ++){
for(int j = 1 ; j <= k ; j ++){
for(int w = 1 ; w <= m * k ; w ++){
cout << S[i][w] ;
}
cout << endl ;
}
}
cout << endl ;
return 0 ;
}
G-二进制与一
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 , B , C , D , E , F , G , P , l1 , r1 , l2 , r2 ;
ll t , n , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , sum[maxn] ;
char s[200][1050] , S[200][1050] ;
ll f[maxn][3] ;
int main(){
n = read() ;
m = read() ;
for(int i = 0 ; i <= 35 ; i ++){
ll res = (n >> i) & 1 ;
if(res == 1){
a[i] = 1 ;
}
else{
a[i] = 0 ;
}
}
ll ans = 0 ;
for(int i = 1 ; i <= m ; i ++){
ll rt ;
rt = read() ;
rt -- ;
if(a[rt] == 1){
continue ;
}
ll Rt = -1 ;
for(int j = 0 ; j <= rt ; j ++){
if(a[j] == 1){
Rt = j ;
break ;
}
}
if(Rt == -1){
ans += (1 << rt) ;
a[rt] = 1 ;
}
else{
for(int j = Rt ; j < rt ; j ++){
if(a[j] == 0){
ans += (1 << j) ;
}
}
ans += (1 << Rt) ;
for(int j = Rt ; j < rt ; j ++){
a[j] = 0 ;
}
a[rt] = 1 ;
}
// cout << ans << endl ;
}
cout << ans << endl ;
return 0 ;
}
H-Genshin 玩家
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < ll , ll > PII ;
const int maxn = 1e6 + 7 ;
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 , m , k , yy , x2 , y2 , a[maxn] , b[maxn] , sum[maxn] ;
string s ;
vector < PII > q , p ;
int main(){
cin >> s ;
int len = s.length() ;
for(int i = 0 ; i < len ; i ++){
if(i + 6 < len){
string S = "" ;
for(int j = i ; j <= i + 6 ; j ++){
S = S + s[j] ;
}
if(S == "Genshin"){
q.push_back({i + 1 , i + 7}) ;
}
}
if(i + 5 < len){
string S = "" ;
for(int j = i ; j <= i + 5 ; j ++){
S = S + s[j] ;
}
if(S == "player"){
p.push_back({i + 1 , i + 6}) ;
}
}
}
ll ans = 0 ;
for(int i = 0 ; i < (int)q.size() ; i ++){
for(int j = 0 ; j < (int)p.size() ; j ++){
if(p[j].first >= q[i].second){
ans ++ ;
}
}
}
cout << ans << endl ;
return 0 ;
}
喜欢作者的记得点个关注!