Educational Codeforces Round 118 (Rated for Div. 2)

在这里插入图片描述

#include<iostream>
#include <algorithm>
#include<cmath>
using namespace std;



//快速幂
long long qpow(long long x, long long base) {
	long long ans = 1;
	while (base) {
		if (base & 1) {//如果最后一位为1
			ans *= x;
		}
		x = x * x;//不用else 都要执行的
		base >>= 1;//记得有赋值操作
	}
	return ans;
}
//求位数
int logg(int x) {
	int t = 0;
	while (x) {
		++t;
		x = x / 10
		//x=x >> 1;这个是除以2啊我晕
	}
	return t;
}

int main() {
	int t, x1, x2;
	long long p1, p2;
	cin >> t;
	while (t--) {
		cin >> x1 >> p1 >> x2 >> p2;
		//先是比较总共的位数
		if (logg(x1) + p1 > logg(x2) + p2)
			cout << ">" << endl;
		else if (logg(x1) + p1 < logg(x2) + p2)
			cout << "<" << endl;
		else {
			//位数相同 从后面0的差值算出具体数值大小再比较
			if (p1 - p2 < 0) {
				if(qpow(10,p2 - p1)*x2-x1 < 0)
					cout << ">" << endl;
				else if(qpow(10, p2 - p1)*x2 - x1 == 0)
					cout << "=" << endl;
				else
					cout << "<" << endl;
			}
			else if (p1 - p2 > 0) {
				if (qpow(10, p1 - p2)*x1 - x2 < 0)
					cout << "<" << endl;
				else if (qpow(10, p1 - p2)*x1 - x2 == 0)
					cout << "=" << endl;
				else
					cout << ">" << endl;
			}
			else {
				if(x1<x2)
					cout << "<" << endl;
				else if (x1 - x2 == 0)
					cout << "=" << endl;
				else
					cout << ">" << endl;
			}
		}
	}
}

接下来为补题:
B题参考自大佬2
在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
	//使cin和cout不缓存,速度和scanf printf 差不多
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int t, n, * a, min;
	cin >> t;
	while (t--) {
		cin >> n;
		a = new int[n];
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		sort(a, a+n);
		min = a[0];
		for (int i = 1; i < n/2+1; ++i) {
			//来自于大佬2:
			//对最小值进行取模后的结果一定会比最小值要小,因此该数字一定不存在于数组中。
			cout << a[i] << " "<<min << endl;
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值