zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 86 (Rated for Div. 2) 题解

     白给题1

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main () {
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	int t;
    	cin >> t;
    	while(t--) {
    		ll x, y;
    		ll a, b;
    		cin >> x >> y >> a >> b;
    		ll ans = 0;
    		ans = abs(x - y) * a + min(x, y) * min(b, 2 * a);
    		cout << ans << endl;
    	}
    }
    

     

     白给题2

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main () {
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	int t;
    	cin >> t;
    	bool endd = 0;
    	while(t--) {
    		endd = 0;
    		string s;
    		cin >> s;
    		if(s.size() == 1) {
    			cout << s << endl;
    			continue;
    		}
    		//为1的情况
    		for(int i = 0; i < s.size() - 1; ++i) {
    			if(s[i] != s[i + 1]) {
    				break;
    			}
    			if(i == s.size() - 2) {
    				cout << s << endl;
    				endd = 1;
    			}
    		}
    		if(endd) {
    			continue;
    		}
    		//为2
    		string ans = "";
    		for(int i = 0; i < s.size() - 1; ++i) {
    			string str;
    			stringstream stream;
    			stream << s[i];
    			str = stream.str();
    			ans += str;
    			if(s[i] == '1' && s[i + 1] == '1') {
    				ans += "0";
    			}
    			if(s[i] == '0' && s[i + 1] == '0') {
    				ans += "1";
    			}
    		}
    		string str;
    		stringstream stream;
    		stream << s[s.size() - 1];
    		str = stream.str();
    		ans += str;
    		cout << ans << endl;
    	}
    }
    

     

     思维题找循环规律

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int f[100010];
    ll getAns(ll sb, int t) {
    	return f[t - 1] * (sb / t) + f[sb % t];
    	//利用循环的特性进行求解
    }
    int main () {
    	ios::sync_with_stdio(false);
    	int t;
    	cin >> t;
    	while(t--) {
    		int a, b, q;
    		cin >> a >> b >> q;
    		int temp = a * b;
    		for(int i = 1; i < temp; ++i) {
    			f[i] = f[i - 1];
    			if(i % a % b != i % b % a) {
    				f[i]++;
    			}
    		}
    		while(q--) {
    			ll l, r;
    			cin >> l >> r;
    			cout << getAns(r, temp) - getAns(l - 1, temp) << " ";
    		}
    		putchar(10);
    	}
    }
    

     后面的题心情好再更新。。。学计组洋文去了

    作者:LightAc
    出处:https://www.cnblogs.com/lightac/
    联系:
    Email: dzz@stu.ouc.edu.cn
    QQ: 1171613053
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
  • 相关阅读:
    虚拟研讨会:如何设计好的RESTful API(转)
    六百字读懂 Git(转)
    情侣相处最佳模式(转)
    UML初览(转)
    日志分析方法概述(转)
    病入膏肓的叮咚小区还有救吗?(转)
    基于Django的Disqus如何支持每月80亿PV(转)
    高质量代码三要素:可读性、可维护性、可变更性(转)
    如何提高代码质量(转)
    管理神话之一:得不偿失的100%利用(转)
  • 原文地址:https://www.cnblogs.com/lightac/p/12788118.html
Copyright © 2011-2022 走看看