7.7竞赛题目选讲(等待更新中,笔者先跑路到第八章了

Zombie's Treasure Chest:

点击查看笔者代码
#include<iostream>
#include<algorithm>
using namespace std;

typedef unsigned long long ull;

ull gcd(ull a, ull b) {
  if(a%b == 0) return b;
  return gcd(b, a%b);
}

int main() {
  int t; 
  cin >> t;
  for(int i = 1; i <= t; i++) {
  	ull n, v1, s1, v2, s2, ans, add = 0;
  	cin >> n >> v1 >> s1 >> v2 >> s2;
  	if(v1 < v2) { 
	  int temp = v1; v1 = v2; v2 = temp; 
	  temp = s1; s1 = s2; s2 = temp;
	}
	ull dis = gcd(v1, v2); 
  	ull mul = v1*v2/dis, base = max(v1*s2/dis, v2*s1/dis);
  	if(n/mul > 1) { ans = (n/mul-1)*base; n = n % mul + mul; }
  	else ans = 0;
  	int len = n / v1; 
  	for(int j = 0; j <= len; j++) 
  	  add = max(add, j*s1+(n-j*v1)/v2*s2);
    cout << "Case #" << i << ": " << ans+add << endl;
  }
  return 0;
} 
posted @   banyanrong  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示