• Educational Codeforces Round 90 (Rated for Div. 2) A~C


    直接判断单价和单买就可以


    #include<bits/stdc++.h>
    #include<string.h>
    using namespace std;
    #define rep(i,j,k) for(LL i=(j); i<(k); ++i)
    #define pb push_back
    #define PII pair<LL,LL>
    #define PLL pair<long long, long long>
    #define ini(a,j) memset(a,j,sizeof a)
    #define rrep(i,j,k) for(LL i=j; i>=k; --i)
    #define fi first
    #define se second
    #define LL long long
    #define beg begin()
    #define ed end()
    #define all(x) x.begin(),x.end()
    
    
    int main(int argc, char const *argv[])
    {
    	// #define DEBUG
        	#ifdef DEBUG
    		freopen("1.dat","r",stdin);
    		freopen("ans.dat","w",stdout);
    	#endif
    	LL _;
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
    	cin>>_;
    	while(_--){
    		LL a,b,c;
    		cin>>a>>b>>c;
    		LL ans1=-1;
    		LL ans2=-1;
    		if(a<c)
    			ans1 = 1;
    		if(a*b>c)
    			ans2 = b;
    		cout<<ans1<<" "<<ans2<<endl;
    	}
    	return 0;
    }
    

    仔细思考会发现,少的那个总会被消除完的,因为不可能使得两个都有剩下而不相邻

    #include<bits/stdc++.h>
    #include<string.h>
    using namespace std;
    #define rep(i,j,k) for(LL i=(j); i<(k); ++i)
    #define pb push_back
    #define PII pair<LL,LL>
    #define PLL pair<long long, long long>
    #define ini(a,j) memset(a,j,sizeof a)
    #define rrep(i,j,k) for(LL i=j; i>=k; --i)
    #define fi first
    #define se second
    #define LL long long
    #define beg begin()
    #define ed end()
    #define all(x) x.begin(),x.end()
    
    // const int N = 1e5+10;
    // int a[N];
    
    int main(int argc, char const *argv[])
    {
    	// #define DEBUG
        	#ifdef DEBUG
    		freopen("1.dat","r",stdin);
    		freopen("ans.dat","w",stdout);
    	#endif
    	LL _;
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
    	cin>>_;
    	while(_--){
    		// 少的那个总是可以消除完的
    		string s;
    		cin>>s;
    		int c = count(all(s),'0');
    		int c2 = s.length()-c;
    		c = min(c, c2);
    		if(c&1)
    			cout<<"DA"<<endl;
    		else
    			cout<<"NET"<<endl;
    
    	}
    	return 0;
    }
    

    记录一波前缀和,每次向后找更小的负数,记录到答案的cnt里就可以


    #include<bits/stdc++.h>
    #include<string.h>
    using namespace std;
    #define rep(i,j,k) for(LL i=(j); i<(k); ++i)
    #define pb push_back
    #define PII pair<LL,LL>
    #define PLL pair<long long, long long>
    #define ini(a,j) memset(a,j,sizeof a)
    #define rrep(i,j,k) for(LL i=j; i>=k; --i)
    #define fi first
    #define se second
    #define LL long long
    #define beg begin()
    #define ed end()
    #define all(x) x.begin(),x.end()
    
    const int N = 1e6+10;
    int a[N];
    
    int main(int argc, char const *argv[])
    {
    	// #define DEBUG
        	#ifdef DEBUG
    		freopen("1.dat","r",stdin);
    		freopen("ans.dat","w",stdout);
    	#endif
    	LL _;
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
    	cin>>_;
    	while(_--){
    		string s;
    		cin>>s;
    		a[0]=0;
    		rep(i,1,s.length()+1)
    			if(s[i-1]=='+')
    				a[i]=a[i-1]+1;
    			else
    				a[i] =a[i-1]-1;
    		// 遇到的每一个负数,都是要进去一次的
    		LL ma = 0;
    		LL ans = 0;
    		LL used = 0;
    		rep(i,1,s.length()+1){
    			if(a[i]>=0)
    				continue;
    			if(a[i]<ma){
    				ans += i*(abs(a[i])-used);
    				used = abs(a[i]);  // 用了a[i]次
    				ma = a[i];
    				// cout<<a[i]<<" "<<i<<endl;
    			}
    		}
    
    		ans += s.length();
    		cout<<ans<<endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    微信小程序,答题问卷,单选,多选混合在一个借口,前端怎么循环
    react 从0到1
    react从0到0
    es6 系统总结
    点击页面的某个元素,弹出这个元素的索引(是第几个)
    js return的用法
    安装golang.org/x/*
    完美解决从github上下载东西慢的方法
    初探golang和应用其框架 gin 的 使用教程(一)安装篇
    CentOS7安装go开发环境
  • 原文地址:https://www.cnblogs.com/Crossea/p/13193913.html
Copyright © 2020-2023  润新知