冰雹猜想

· · 个人记录

#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
bool copyToClipboard(const std::string& text) {
    // 打开剪贴板
    if (!OpenClipboard(NULL)) {
        std::cerr << "Unable to open clipboard." << std::endl;
        return false;
    }

    // 清空剪贴板内容
    if (!EmptyClipboard()) {
        std::cerr << "Unable to empty clipboard." << std::endl;
        CloseClipboard();
        return false;
    }

    // 分配内存并将文本复制到剪贴板
    size_t size = (text.size() + 1) * sizeof(char);
    HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, size);
    if (hGlobal == NULL) {
        std::cerr << "Unable to allocate global memory." << std::endl;
        CloseClipboard();
        return false;
    }

    // 将文本复制到分配的内存中
    memcpy(GlobalLock(hGlobal), text.c_str(), size);
    GlobalUnlock(hGlobal);

    // 将文本放入剪贴板
    if (SetClipboardData(CF_TEXT, hGlobal) == NULL) {
        std::cerr << "Unable to set clipboard data." << std::endl;
        GlobalFree(hGlobal);
        CloseClipboard();
        return false;
    }

    // 关闭剪贴板
    CloseClipboard();
    return true;
}
int y[114514]; char qwq[114514];
int main() {
//  int mx = -1, mxn = -1;
//  for (int __n = 1; __n <= 100000; __n++) {
//      int n = __n, idx = 0;
//      while (n != 1) {
//          idx++;
//          if (n & 1) n = 3 * n + 1;
//          else n /= 2;
//      }
//      if (idx > mx) mx = idx, mxn = __n;
//  }
//  cout << mxn << '\n';
//  system("pause");

    int n, idx = 0; cin >> n;
    while (n != 1) {
        y[idx++] = n;
        if (n & 1) n = 3 * n + 1;
        else n /= 2;
    }
    int y_max = *max_element(y, y + idx);
    const int B = max(1, y_max * 2 / idx);
//  const int B = 100;

    string CIALLO = "";
    for (int i = 0; i < idx; i++) sprintf(qwq, "A_{%d} = (%d, %d)\n", i, i * B, y[i]), CIALLO += string(qwq);
    for (int i = 1; i < idx; i++) sprintf(qwq, "y = %.5lf x + (%d) \\{%d <= x <= %d\\}\n", 1.0 * (y[i] - y[i - 1]) / B, y[i] - (y[i] - y[i - 1]) * i, B * (i - 1), B * i), CIALLO += string(qwq);
//  for (int i = 0; i < idx; i++) sprintf(qwq, "A_{%d} = (%d, %.5lf)\n", i, i * B, log(y[i]) * B), CIALLO += string(qwq);
//  for (int i = 1; i < idx; i++) sprintf(qwq, "y = %.5lf x + (%.5lf) \\{%d <= x <= %d\\}\n", log(y[i]) - log(y[i - 1]), log(y[i]) * B - i * B * (log(y[i]) - log(y[i - 1])), (i - 1) * B, i * B), CIALLO += string(qwq);
    cerr << "TIME = " << idx << '\n';
    cerr << CIALLO << '\n';
    if (copyToClipboard(string(CIALLO))) cerr << "ok";
    return 0;
}