• Codeforces Round #730 (Div. 2)


    A. Exciting Bets
    对两个数同时加或者减,求最大gcd,就是abs(a-b),最后就是0,Δ;Δ,2Δ;2Δ,3Δ的情况

    代码
    
    int main()
    {
    	ios::sync_with_stdio(false); cin.tie(nullptr);
    	int t;
    	cin >> t;
    	while (t--) {
    		ll a, b;
    		cin >> a >> b;;
    		if (a == b)
    			cout << 0 << " " << 0 << endl;
    		else {
    			ll dif = abs(a - b);
    			ll ans = min(a % dif, abs(dif - a % dif));
    			cout << dif << " " << ans << endl;
    		}
    	}
    }
    

    B. Customising the Track
    要求最小的差值,所以尽量让每个数相等。在两两组合中,n和n+1的组合有num1*num2种。
    (我当时直接把数组变成n,n,..n+1,n+1..,就比较直观了)

    代码
    
    ll a[N];
    int main()
    {
    	ios::sync_with_stdio(false); cin.tie(nullptr);
    	int t;
    	cin >> t;
    	while (t--) {
    		int n;
    		cin >> n;
    		ll sum = 0;
    		for (int i = 1; i <= n; i++) {
    			cin >> a[i];
    			sum += a[i];
    		}
    		ll re = sum % n;
    		ll ans = re * (n - re);
    		cout << ans << endl;
    	}
    }
      

    C. Need for Pink Slips
    求选到 Pink Slips的概率,比赛时不会。
    主要是用dfs遍历概率树,还有精度(就是不能写成>0,因为浮点数有误差,在多次算之后会影响结果)。

    代码
    
    const long double eps = 1e-6;
    double c, m, p, v, ans;
    void dfs(double c, double m, double p, int i, double now) {
    	if (c > eps) {
    		if (c > v) {
    			if (m > eps) dfs(c - v, m + v / 2, p + v / 2, i + 1, c * now);
    			else dfs(c - v, 0, p + v, i + 1, c * now);
    		}
    		else {
    			if (m > eps) dfs(0, m + c / 2, p + c / 2, i + 1, c * now);
    			else dfs(0, 0, p + c, i + 1, c * now);
    		}
    	}
    	if (m > eps) {
    		if (m > v) {
    			if (c > eps) dfs(c + v / 2, m - v, p + v / 2, i + 1, m * now);
    			else dfs(0, m - v, p + v, i + 1, m * now);
    		}
    		else {
    			if (c > eps) dfs(c + m / 2, 0, p + m / 2, i + 1, m * now);
    			else dfs(0, 0, p + m, i + 1, m * now);
    		}
    	}
    	ans += p * i * now;
    }
    int main()
    {
    	ios::sync_with_stdio(false); cin.tie(nullptr);
    	int t;
    	cin >> t;
    	while (t--) {
    		cin >> c >> m >> p >> v;
    		ans = 0;
    		dfs(c, m, p, 1, 1);
    		cout << fixed << setprecision(12)<< ans << endl;
    	}
    }     
      

    D1. RPD and Rap Sheet (Easy Version)
    让我们猜密码,不过每次答案会变化,如果猜n,pas=pas xor n。
    利用xor2次又变回来的性质,先猜0,再猜1(因为答案变了,所以是0xor1),如果不对相当于答案只xor1了,再猜2(实际为1xor2)

    代码
    
    int main()
    {
    	//ios::sync_with_stdio(false); cin.tie(nullptr);
    	int t;
    	scanf("%d", &t);
    	while (t--) {
    		int n, k;
    		scanf("%d%d", &n, &k);
    		int tmp = 0, ba = 0;
    		for (int i = 1; ba == 0; i++) {
    			printf("%d
    ", tmp);
    			fflush(stdout);
    			scanf("%d", &ba);
    			tmp = (i - 1) ^ i;
    		}
    		fflush(stdout);
    	}
    }
      
  • 相关阅读:
    Java中HashMap底层实现原理(JDK1.8)源码分析
    java io系列01之 "目录"
    数据结构与算法系列 目录
    Java 集合系列目录(Category)
    ls参数
    在PATH路径中添加新的路径
    目录相关的操作
    chmod
    属性类型
    ls -al
  • 原文地址:https://www.cnblogs.com/lingshi321/p/14984354.html
Copyright © 2020-2023  润新知