php除了做网站/公司网站免费自建
A
给我感觉就是机组流水线的计算…
显然,对于任意一个点来说;其贡献的不满意度在最理想的情况下是y/x,y是结束时间,x是间隔y/x,y是结束时间,x是间隔y/x,y是结束时间,x是间隔
当n较小的情况下,假设n个点,那么
ans=(n−1)+(n−2)+...+1ans=(n-1)+(n-2)+...+1ans=(n−1)+(n−2)+...+1,直接等差数列求和即可;
当n较大的情况下,在前面一些点都是处理理想状态,每个点能贡献y/xy/xy/x;
而后面的点因为没人继续参赛了,所以提供的贡献会不断下降1,因此也是像n较小的情况下,用等差数列求和;
也就是最后的y/xy/xy/x个人享受"流水线"低效的过程…
附一张与此题无关的图,机组流水线的…
Code
#include <iostream>using namespace std;typedef long long ll;ll n,x,y,ans;int main()
{int t;cin >> t;while(t--){cin >> n >> x >> y;ll z = y/x;//y<x,z=0if(z>=n){ans = n*(n-1)/2;cout << ans << '\n';}else{ans = n*z - (1+z)*z/2;cout << ans << '\n';}}return 0;
}
B
#include <iostream>using namespace std;const int N = 1e5+10;char str[N];typedef long long ll;ll n,q,l,r,s[N];ll query(ll l,ll r){return s[r] - s[l-1];
}
int main()
{std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);cin >> n >> q;cin >> (str+1);for(int i=1;i<=n;++i){s[i] = s[i-1] + str[i]-'a'+1;}while(q--){cin >> l >> r;cout << query(l,r) << '\n';}return 0;
}
C
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>using namespace std;const int N = 200010;typedef long long ll;ll n,k,x,a[N];priority_queue<ll,vector<ll>,greater<ll> >pq;int main()
{cin >> n >> k >> x;for(int i=1;i<=n;++i){cin >> a[i];}sort(a+1,a+1+n);ll ans = 1;for(int i=1;i<=n-1;++i){if(a[i+1]-a[i]<=x) continue;pq.push(a[i+1]-a[i]);}ll val,t;while(!pq.empty()){val = pq.top();pq.pop();if(val%x==0){t = val/x - 1;}else{t = val/x;}if(k>=t){k-=t;}else{++ans;}}cout << ans << '\n';return 0;
}
D
#include <iostream>
#include <algorithm>using namespace std;const int N = 1e5+10;typedef long long ll;struct Node{ll a,b;
}c[N];bool cmp(Node p,Node q){return p.b < q.b;
}int main(){int n;cin >> n;for(int i=1;i<=n;++i){cin >> c[i].a >> c[i].b; }sort(c+1,c+1+n,cmp);int l = 1,r = n;ll tot = 0,ans = 0;while(l<=r){if(tot<c[l].b){ll num = min(c[r].a,c[l].b-tot);tot+=num;ans+=num<<1;c[r].a-=num;if(!c[r].a) --r;}else{tot+=c[l].a;ans+=c[l].a;++l;}}cout << ans << '\n';return 0;
}