设计师调度分配
在一个创意工作室中,三位设计师李工、王工和张工分别负责三项独立的模型制作任务。李工完成任务需要a1秒,王工需要a2秒,张工需要a3秒。工作室的建模平台一次只能容纳两名设计师工作,第三位设计师需等待,直到平台空闲(即当前一位设计师完成任务离开)才能开始工作。所有模型全部完成时,项目才算正式交付。
现在,经理希望合理调度设计师的工作顺序,以最短时间完成所有任务。请你计算三位设计师完成三件模型的最小总时间。
输入格式3 5 7
输出结果8
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| #include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { vector<int> numbers; int a1, a2, a3, c; for (int i = 0; i < 3; i++) { int a; cin >> a; numbers.push_back(a); } sort(numbers.begin(), numbers.end()); a1 = numbers[0]; a2 = numbers[1]; a3 = numbers[2]; c=a1 + a2;
if(c >= a3){ cout << c << endl; } else{ cout << a3 << endl;
} return 0; }
|
妈妈的菜单
小蓝是个挑食但又容易饿的孩子。午餐时间,妈妈为他准备了 10 道菜,并写下了一份菜单。菜单上的每道菜都有一个“饱腹值”,表示吃下这道菜能增加多少饱腹感。
妈妈会严格按照菜单的顺序,从第一道菜开始逐一端上餐桌。小蓝可以选择吃或不吃当前这道菜。然而,一旦他决定不吃某一道菜,妈妈就会认为他已经吃饱了,并停止端上后续的所有菜肴。
小蓝虽然容易饿,但也不喜欢吃得太撑的感觉。因此,他希望午餐后自己的饱腹值能停留在 100 附近。
现在,请你根据小蓝的情况计算,他最终会获得的饱腹值是多少。
注意:如果存在两种选择,它们与 100 的差距相同(例如,饱腹值为 98 和 102),他总是会选择那个更高的值——毕竟,对于一个正在长身体的孩子来说,吃撑一点总比饿着肚子好。
输入格式20 10 10 10 10 10 10 10 15 15
输出格式105
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <iostream> #include <cmath> using namespace std;
int main() { short food[10]; int best = 0; for (int i = 0; i < 10; i++) { cin >> food[i]; } int current = 0; for (int i = 0; i < 10; i++) { current += food[i]; if (abs(current - 100) < abs(best - 100)) { best = current; } else if (abs(current - 100) == abs(best - 100)) { if (current > best) { best = current; } } } cout << best << endl; return 0; }
|
挑选题目
两位资深的审题专家,小蓝和小桥,各自收到了N道题目。小蓝收到的题目难度依次为 A1,A2,A3…An,小桥收到的题目难度依次为B1,B2,B3…Bn,为了准备即将举行的竞赛,他们需要从各自收到的题目中选出一道,用于竞赛。通过商量,两人决定通过一种特殊的方式来选择题目:两人轮流删除一道自己手中的题目,直到各自只剩下一道题目。小蓝先删除,然后小桥删除,依此交替进行,直到最后两人手中都只剩下一道题目。小蓝希望最终两人剩下的两道题目的难度差尽可能大,而小桥则希望难度差尽可能小。假设两人都采取最优策略,请问最终两人剩下的两道题目的难度差的绝对值是多少?
for双层循环示例(cpp)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #include<stdio.h> int main() { int a[999],b[999]; int min=9999999; int max=-1; int n; cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) {
} } return 0; }
|
我写的代码(cpp)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #include<iostream> #include<vector> #include <algorithm> using namespace std; int main(){ int n; vector<int> lan; vector<int> qiao; vector<int> c; vector<int> d; cin >> n; c.resize(n); d.resize(n); int num; while(cin >> num){ lan.push_back(num); if (cin.peek() == '\n') { break; } } while(cin >> num){ qiao.push_back(num); if (cin.peek() == '\n') { break; } } for(int i = 0;i < n;i++){ for(int j = 0;j < n;j++){ c[j]=abs(lan[i]-qiao[j]); } int small = *min_element(c.begin(), c.end()); d[i]=small; } int big = *max_element(d.begin(), d.end()); cout << big << endl; return 0; }
|
copilot(cpp)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <bits/stdc++.h> using namespace std;
int main() { ios::sync_with_stdio(false); cin.tie(nullptr);
int n; if (!(cin >> n)) return 0; vector<int> A(n), B(n); for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i < n; i++) cin >> B[i];
sort(B.begin(), B.end());
auto nearestDistInB = [&](int x) { auto it = lower_bound(B.begin(), B.end(), x); int dist = INT_MAX; if (it != B.end()) dist = min(dist, abs(*it - x)); if (it != B.begin()) { --it; dist = min(dist, abs(*it - x)); } return dist; };
int ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, nearestDistInB(A[i])); }
cout << ans << '\n'; return 0; }
|
Author:
Lyxy-szs
Permalink:
http://lyxy-szs.github.io/2025/09/14/bluebridge/
Slogan:
永远相信美好的事情即将發生?