1. 程式人生 > 實用技巧 >8.3集訓

8.3集訓

上午

第一題

其中\(n \leq 1e18\)

#include <bits/stdc++.h>
#define int long long
#define debug
using namespace std;

const int N = 1e5+66;

int n;

inline int thestars() {
   cin >> n;
   int l = 1, r = sqrt(n)*2+1;
   int mo = 2*n-2;
   while (l < r) {
      int mid = (l + r)>>1;
      if (mid*(mid+1) >= mo) r = mid;
      else l = mid+1;
   }
   cout << l;
   return 0;
}

int youngore = thestars();

signed main() {;}

第二題

有百分之二十的暴力,但是需要LL

#include <bits/stdc++.h>
#define int long long
#define debug
using namespace std;

inline long long read() {
   long long s = 0, f = 1; char ch;
   while(!isdigit(ch = getchar())) (ch == '-') && (f = -f);
   for(s = ch ^ 48;isdigit(ch = getchar()); s = (s << 1) + (s << 3) + (ch ^ 48));
   return s * f;
}

const int N = 3e5+66, INF = 214748364000000;

int n, res = INF;
int vis[N];

struct node{int a, t, v;}yhm[N];

inline void dfs(int x, int num, int ans, int fangyu) {
   vis[x] = 1;
   if (num == n) {
      res = min(res, ans);
      return;
   }
   for (int i = 1; i <= n; ++ i) {
      if (!vis[i]) {
         int now_ans = (yhm[i].a-fangyu)*yhm[i].t+ans;
         int now_fangyu = yhm[i].v + fangyu;
         dfs(i, num+1, now_ans, now_fangyu);
         vis[i] = 0;
      }
   }
}

inline int thestars() {
   n = read();
   for (int i = 1; i <= n; ++ i)
      yhm[i].a = read(), yhm[i].t = read(), yhm[i].v = read();
   for (int i = 1; i <= n; ++ i) {
      memset (vis, 0, sizeof vis);
      dfs(i, 1, yhm[i].a*yhm[i].t, yhm[i].v);
   }
   cout << res;
   return 0;
}

int youngore = thestars();

signed main() {;}

下面給出正解:

#include <bits/stdc++.h>
#define int long long
#define debug
using namespace std;

inline long long read() {
   long long s = 0, f = 1; char ch;
   while(!isdigit(ch = getchar())) (ch == '-') && (f = -f);
   for(s = ch ^ 48;isdigit(ch = getchar()); s = (s << 1) + (s << 3) + (ch ^ 48));
   return s * f;
}

const int N = 4e5+66;

int n, res, fangyu;

struct node {int a, t, v; double anzhi;}yhm[N];

inline int cmp(node x, node y){return x.anzhi > y.anzhi;}

inline int thestars() {
   cin >> n;
   for (int i = 1; i <= n; ++ i) {
      yhm[i].a = read(), yhm[i].t = read(), yhm[i].v = read();
      yhm[i].anzhi = (double)yhm[i].v/yhm[i].t;
   }
   sort (yhm+1, yhm+n+1, cmp);
   for (int i = 1; i <= n; ++ i) {
      res += (yhm[i].a - fangyu)*yhm[i].t;
      fangyu += yhm[i].v;
   }
   cout << res;
   return 0;
}

int youngore = thestars();

signed main() {;}

第三題

我的程式碼:

沒顧上寫呢

下午

rqj學長講課