This question is directly simulated.
However, I hung the Qaq on the last two points. The only thing you should pay attention to is accuracy... If it is used to convert the value behind double to an integer, we forget to use Longlong... Sad
#include <cstdio>#include <cstring>#include <cmath>#include <string>#include <iostream>#include <algorithm>#include <queue>#include <set>#include <map>using namespace std;typedef long long ll;#define pii pair<int, int>#define mkpii make_pair<int, int>#define pdi pair<double, int>#define mkpdi make_pair<double, int>#define pli pair<ll, int>#define mkpli make_pair<ll, int>#define rep(i, n) for(int i=0; i<(n); ++i)#define for1(i,a,n) for(int i=(a);i<=(n);++i)#define for2(i,a,n) for(int i=(a);i<(n);++i)#define for3(i,a,n) for(int i=(a);i>=(n);--i)#define for4(i,a,n) for(int i=(a);i>(n);--i)#define CC(i,a) memset(i,a,sizeof(i))#define read(a) a=getint()#define print(a) printf("%d", a)#define dbg(x) cout << (#x) << " = " << (x) << endl#define error(x) (!(x)?puts("error"):0)#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }#define printarr1(a, b) for1(_, 1, b) cout << a[_] << ‘\t‘; cout << endlinline const int getint() { int r=0, k=1; char c=getchar(); for(; c<‘0‘||c>‘9‘; c=getchar()) if(c==‘-‘) k=-1; for(; c>=‘0‘&&c<=‘9‘; c=getchar()) r=r*10+c-‘0‘; return k*r; }inline const int max(const int &a, const int &b) { return a>b?a:b; }inline const int min(const int &a, const int &b) { return a<b?a:b; }const int N=200005;int a[N], b[N], n, m, bn, an;const double eps=1e-5;char s[10];int main() {read(n); read(m);for1(i, 1, n) {scanf("%s", s);int t=getint();if(s[0]==‘T‘) b[++bn]=t;else { if(t<m) a[++an]=t; }}sort(b+1, b+1+bn);sort(a+1, a+1+an);int i=1, j=1;double pos=0, ans=0;while(i<=an && j<=bn) {double sp=(1.0/(double)(i+j-1));double at=((double)a[i]-pos)*(i+j-1)+ans;if(at<(double)(b[j])) {pos=a[i++];ans=at;}else {pos+=sp*((double)b[j]-ans);if(pos+eps>m) break;ans=(double)b[j++];}}while(i<=an && (pos+eps)<=m) { ans+=((double)a[i]-pos)*(double)(i+j-1); pos=a[i++]; }while(j<=bn && (pos+eps)<=m) { pos+=(1.0/(double)(i+j-1))*((double)b[j]-ans); ans=(double)b[j++]; }if(pos+eps<=m) ans+=(double)(m-pos)*(double)(i+j-1);printf("%lld\n", (ll)(ans+eps));return 0;}
Background
Who is the most virtual in the attached IDC? Class 2 and Class 1 ***! It feels good, right?
Description
Today, the zombie czy drove an excavator to school (......). But he found that his MZ was full, so he met many of his MZ along the way. At a 1 km/min speed (= 60 km/h ......) Drive the excavator forward. He finds that he will only encounter MZ at a certain time or a certain distance. Every time you encounter Mz, czy will not hesitate to take them along (^_^ ). But he is so imaginary that when I have an Mz, his speed drops to 1/(I + 1 ). Specifically, at the beginning, czy was moving forward at a speed of 1 km/min. The speed of one MZ was changed to 1/2/min, and the speed of two was changed to 1/3/min ...... And so on. Now, the question is, how long does it take for each MZ to arrive at school.
Format
Enter 2 numbers N and m in the first line, indicating the MZ number and the distance between czy and the school (km)
The next two to n + 1 rows are composed of strings and numbers.
Dist X indicates that an MZ occurs when the distance reaches x km.
Time X indicates that an MZ occurs when the time reaches X min.
Output an integer to indicate the time the school arrived. If division is not allowed, you can directly output the integer part.
Sample Input
2 20
Time 3
Dist 10
Sample output
47
Data range
For 30% of the data, n, m <= 50
For 50% data, n, m <= 2000
For 100% data, n, m <= 200000, x <= 10 ^ 9, ensure that all input numbers are integers.
[Noip simulation questions] excavator (simulation questions + accuracy)