赶火车
分别求出n和m的期望用m的期望乘上m除以n加上n的期望就是总的期望
#include <bits/stdc++.h> using namespace std; int a[15]; int b[15]; int main() { int t,n,m,y; cin>>t; while(t--) { float nn = 0; float mm = 0; cin>>n>>m>>y; for(int i = 0;i < n;i++) { cin>>a[i]; nn += (float)a[i]/n; } for(int i = 0;i < m;i++) { cin>>b[i]; mm += (float)b[i]/m; } float ans = (float)m/n*mm+nn; if(ans <= y) cout<<"Go"<<endl; else cout<<"Wait"<<endl; } return 0; }
定理证明
n(n+1)/2 - 1
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; int main() { int t,n; cin>>t; int ans; while(t--) { cin>>n; ans = (n + 1)*n/2 - 1; printf("%d\n",ans%mod); } return 0; }