NC223548. JoiningFlows
描述
输入描述
The first line of input contains an integer k (1 ≤ k ≤ 10), the number of taps. Then followk lines, describing the taps. The i’th of these lines contains the three integers ti, ai, and bi(0 ≤ ti ≤ , 0 ≤ ai ≤ bi ≤ ) describing the i’th faucet.Next follows a line containing an integer r (1 ≤ r ≤ ), the number of new recipies tocheck. Then follows r lines, each describing a recipe. A recipe is described by two integersτ and φ (0 ≤ τ ≤ and 1 ≤ φ ≤ ), where τ is the chocolate temperature and φ thechocolate flow needed for this recipe.
输出描述
For each of the r recipies, print one line with the string “yes” if it is possible to achieve the desired combination of chocolate temperature and flow, and “no” otherwise.
示例1
输入:
2 50 0 100 100 50 100 3 20 75 75 150 75 90
输出:
no yes no
C++(clang++ 11.0.1) 解法, 执行用时: 249ms, 内存消耗: 752K, 提交时间: 2023-07-09 21:11:08
#include<bits/stdc++.h> using namespace std; #define int long long const int N=30; #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int k, r; int maxf, minf, g; struct Node { int t, a, b; }node[N]; bool cmp(Node a, Node b) { return a.t<b.t; } signed main() { IOS cin>>k; for(int i=1;i<=k;i++) { cin>>node[i].t>>node[i].a>>node[i].b; maxf+=node[i].b; minf+=node[i].a; g+=node[i].a*node[i].t; } int r, f, sumn; double t; cin>>r; sort(node+1, node+k+1, cmp); for(int i=1;i<=r;i++) { int mi=0, ma=0; cin>>t>>f; if(f<minf||f>maxf) { cout<<"no"<<endl; continue; } sumn=f-minf; for(int j=1;j<=k;j++) { int x=(node[j].b-node[j].a); if(x<=sumn){ sumn-=x; mi+=node[j].t*x; } else{ mi+=sumn*node[j].t; break; } } sumn=f-minf; for(int j=k;j>=1;j--) { int x=(node[j].b-node[j].a); if(x<=sumn){ sumn-=x; ma+=node[j].t*x; } else{ ma+=sumn*node[j].t; break; } } double maa=(ma+g)*1.0/f, mii=(mi+g)*1.0/f; if(t<=maa&&t>=mii){ cout<<"yes"<<endl; } else cout<<"no"<<endl; } return 0; }