跳到正文

个人记录

终结黑白色棋类游戏!

DrCharley约 4 分钟
原文
文章信息与版本

文章信息

发布
2026年7月30日
收录
2026年11月29日
更新
2026年11月29日
篇幅
约 4 分钟

版本

  1. v1当前
C++
/*
A. temp (1000ms/256MiB) 
题目描述
 
有
  N 
个装置,第
  i
个装置的初始温度为
 t_i
。
给定正整数
 a,b
。1次降温操作需要选择1个装置:被选择的装置温度降低a
 
,其余
  N-1
个装置的温度各降低
 b
。
求最少需要进行多少次降温操作,才能使所有装置的温度都严格小于
 0
。
输入格式
 
第一行三个正整数
 N,a,b
。
第二行 
  N
个整数
 t_i 
,表示各装置的初始温度。
输出格式
 
输出1个非负整数,表示所需的最少操作次数。

对于所有数据:
1 <= N <= 10^5
1 <= a,b <= 10^9
-10^9 <= t_i <= 10^9

目标:优化时间复杂度/debug
*/

#include <vector>
#include <iostream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <array>
#include <memory>
#include <algorithm>
#include <cstdlib>
#include <ctime>
using namespace std;

#define int long long

const int maxn = 1e5+5;
int t[maxn];
int n,a,b,prefixx=0,ans=0;

signed main() {
    cin.tie(0)->sync_with_stdio(false);

    freopen("temp.in","r",stdin);
    freopen("temp.out","w",stdout);

    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++) {
        cin >> t[i];
    }
    sort(t+1,t+n+1);
    if(t[n] + prefixx < 0) ;
    else if(a==b) ans = t[n]/a+1;
    else if(a<=b)while(1){
        t[0]+=b-a;
        prefixx -= b;
        sort(t+1,t+n+1);
        ans++;
        if(t[n] + prefixx < 0) break;
    }
    else while(1){
        t[n]-=a-b;
        prefixx -= b;
        sort(t+1,t+n+1);
        ans++;
        if(t[n] + prefixx < 0) break;
    }
    cout << ans << '\n';
    return 0;
}
C++
/*
C. meteor (1000ms/512MiB) 
题目描述 
给定正整数 n,求有序整数对 (x,y) 的个数,满足 1 <= x,y <= n,且 x/y 可以表示为十进制有限小数。
输入格式 
一行一个正整数 n。
输出格式 
一行一个整数,表示满足条件的有序整数对数量。

1 <= n <= 10^12

todos:
1.暴力枚举2和5的倍数,数目直接*n
2.暴力枚举非2和5的倍数,数目乘以其倍数的个数
3.如何优化?否则 n >= 10^9 TLE
*/

#include<bits/stdc++.h>
using namespace std;

long long n,ans1=0,total=0;

long long calc(long long n){
    ans1=0;
    for(long long i = 1; i <= n; i*=5){
        for(long long j = 1; i*j <= n; j*=2){
            ans1++;
        }
    }
    return ans1*n;
}

int main(){
    cin.tie(0) -> sync_with_stdio(false);
    freopen("meteor.in","r",stdin);
    freopen("meteor.out","w",stdout);
    cin >> n;
    total += calc(n);
    for(int i = 3; i <= n; i++){
        if(i % 2 == 0 || i % 5 == 0) continue;//记得优化
        total += calc(n/i);
    }
    cout << total;
    return 0;
}
原文