1 solutions

  • 0
    @ 2023-12-3 20:55:10

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    using LL=long long;
    using PLL=pair<LL,LL>;
    const LL INF=0x3f3f3f3f3f3f3f3f;
    const double EPS=1e-10;
    
    const int N=1e5+10;
    LL a[N];
    
    void solve() {
    	LL n;
    	cin>>n;
    	for (LL i=1; i<=n; i++)  {
    		LL x;
    		cin>>x>>a[i];
    	}
    	
    	LL ans=1;
    	LL slow=a[n];
    	for (LL i=n-1; i>=1; i--) {
    		if (a[i]>slow) {
    			//cows group up
    		} else {
    			ans++;
    		}
    		slow=min(slow, a[i]);
    	}
    	
    	cout<<ans<<"\n";
    }
    
    int main() {
    	ios::sync_with_stdio(0);
    	cin.tie(0);
    	cout.tie (0);
    	
    	//freopen("cowjog.in", "r", stdin);
    	//freopen("cowjog.out", "w", stdout);
    
    	int T=1;
    	//cin>>T;
    	for (int i=1; i<=T; i++) {
    		//cout<<i<<"\n";
    	    solve();
    	}
    	return 0;
    }
    
    
    • 1

    USACO 2014 December Contest&#44; Bronze —— Problem 3. Cow Jog

    Information

    ID
    1303
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    (None)
    Tags
    (None)
    # Submissions
    0
    Accepted
    0
    Uploaded By