您当前的位置: 首页 > 

minato_yukina

暂无认证

  • 1浏览

    0关注

    138博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Codeforces Educational Codeforces Round 118 (A-E)部分

minato_yukina 发布时间:2021-12-07 23:13:03 ,浏览量:1

A. Long Comparison

题意:给出两个数字,都表示为 x + 后 缀 有 p 个 0 x+后缀有p个0 x+后缀有p个0.比较两个数字的大小 思路:一开始是傻傻地去模拟,暴力地把p个0加在x后面,然而 p p p的有 1 e 6 1e6 1e6,会超时.我的做法是这样的,首先把 x 1 x1 x1变为string,令其长度为 m 1 m1 m1, 首先直接比较 m 1 + p 1 与 m 2 + p 2 m1+p1与m2+p2 m1+p1与m2+p2,谁长谁大.如果相等,把 x 1 与 x 2 补 成 位 数 相 等 的 s t r i n g , 然 后 直 接 比 较 x1与x2补成位数相等的string,然后直接比较 x1与x2补成位数相等的string,然后直接比较

/*
  给出两个整数 都是x + p个0 
  比较该两个整数大小. 
  2 000
  1900
*/
#include
using namespace std;
const int maxn = 3e5+5;
const int INF = 1e9+7;
int main(){
	int T;
	cin>>T;
	while(T--){
		int x1,p1,x2,p2;
		scanf("%d %d %d %d",&x1,&p1,&x2,&p2);
		string s1,s2;
		s1 = to_string(x1);s2 = to_string(x2);
		int m1 = s1.length();int m2 = s2.length();
		if(m1+p1!=m2+p2){
			if(s1.length()+p1>s2.length()+p2) cout            
关注
打赏
1663570241
查看更多评论
0.0442s