题目描述

One panda named orz is playing a interesting game, he gets a big integer Num and an integer K. In this game, he can exchange two single numbers in Num. For example, he can get 1243 from 3241 by exchange 1 and 3.But orz can exchange at most K times. So what’s the biggest number after at most K times operations?

However, a VIP (Very Important Panda) of ACM/OPPC (Orz Panda Programming Contest) comittee thought this problem was too hard for Orz Pandas. So he simplified this problem with constraint K=1. Your task is to solve the simplified problem.

输入

Multiple cases. For each case:
The first line is an integer Num. 0 ≤ Num ≤ 101000, and it is guaranteed that Num is a legal integer and doesn’t contain any leading zero

输出

For each test case, print the biggest number after at most 1 times operation in a line.

--正文
字符串读取数,贪心找可能的数进行交换
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
char num[1001];int findMax(char* num){int len = strlen(num);int max = -1,maxi;int i;for (i=0;i<len;i++){if (num[i] - '0' >= max) {max = num[i] - '0';maxi = i;}}return maxi;
}int main(){while (scanf("%s",num) != EOF){char* begin = num;int len = strlen(num);int total = 0;bool over = false;while (!over){int maxi = findMax(&num[total]) + total;int now = total;while (num[now] == num[maxi] && now < maxi) now++;if (now == maxi) {total = maxi+1;if (num[total] == '\0') break;continue;}else {char temp = num[now];num[now] = num[maxi];num[maxi] = temp;break;}}printf("%s\n",begin);}return 0;
}

转载于:https://www.cnblogs.com/ToTOrz/p/6135347.html

XidianOJ 1123 K=1 Problem of Orz Pandas相关推荐

  1. XidianOJ 1195 Industry of Orz Pandas

    --正文 贪心 排序好慢慢找就好 #include <iostream> #include <cstring> #include <cstdio> #include ...

  2. XidianOJ 1099 A simple problem

    题目描述 一个长度为N的数组A, 所有数都是整数 ,0 <= A[i] <= 1000000,1 <= i <= N,1 <= N <= 100000,对于 任意i ...

  3. 问题 K: Sequence Problem (III) : Array Practice

    题目描述 整数序列是一串按特定顺序排列的整数,整数序列的长度是序列中整数的个数,不可定义长度为负数的整数序列. 两整数序列A.B的和定义为一个新的整数序列C,序列C的长度是A.B两者中较长的一个,序列 ...

  4. Gym102870 2020-2021 “Orz Panda” Cup Programming Contest 补题记录

    D. Data Structure Master and Orz Pandas 树上期望dp 列个式子跑一遍树形dp就做完了 场上剩半小时才开这题 没写出来亏死 #include<bits/st ...

  5. 2020双周训练训练日志

    第 3 次双周训练 VP A - 6789 签到题,按照题意模拟就行了,由于 lincong 将题目中的"中心对称"看成了"轴对称",导致 WA 了三发还不知道 ...

  6. 【统计学习方法】K近邻对鸢尾花(iris)数据集进行多分类

    本文摘要 · 理论来源:[统计学习方法]第三章 K近邻 · 技术支持:pandas(读csv).collections.Counter(统计).numpy.sklearn.neighbors.KNei ...

  7. 读取excel数据 画k线 成交量图

    # -*- coding: utf-8 -*- """ Created on Tue Mar 23 18:32:15 2021@author: ""& ...

  8. python 通达信板块_[python]沪深龙虎榜数据导入通达信的自选板块,并标注于K线图上...

    将沪深龙虎榜数据导入通达信的自选板块,并标注于K线图上 原理:python读取前一次处理完的计算5日后涨跌幅输出的csv文件 文件名前加"[paint]" 安照通达信的画图文件和板 ...

  9. 聚类k值确定--肘部法则

     k-means是以最小化样本与质点平方误差作为目标函数,将每个簇的质点与簇内样本点的平方距离误差和(sum of the squared errors,SSE,误差平方和)称为畸变程度(distor ...

最新文章

  1. DNS MX记录一定要放在A记录之前
  2. c++入门代码_Golang Gin 实战(一)| 快速安装入门
  3. 李宏毅深度学习——Tips for Deep Learning
  4. 程序员修神之路--做好分库分表其实很难之二
  5. 我来告诉你为什么中国民营企业管理失败的原因!
  6. go web db每次关闭_竟然不用写代码!一款可视化 Web 管理后台生成工具
  7. Python之路(二)Python基础
  8. Okhttp之CacheInterceptor简单分析
  9. pandas读取csv文件数据并对指定字段分类使用matplotlib在一张图里画四张折线图子图
  10. sql server 连接
  11. matlab计算潮流,matlab潮流计算
  12. NVIDIA显卡刷BIOS教程,秒变超频显卡,将显卡性能发挥到极致!
  13. 数据挖掘肿瘤预测_肿瘤分析数据挖掘及信息解读
  14. 要重复多少次变成潜意识_从骨子里的改变-潜意识的力量!
  15. 学习笔记【Java 虚拟机②】垃圾回收
  16. 证券公司信息化2-投资银行业务是做什么的,怎样赚钱,IT在里边起到什么作用?
  17. 生日礼物codeGift
  18. 互联网史-chinaren与校内
  19. Python基础第一课
  20. 类似Cryptonom的区块链游戏开发细节介绍

热门文章

  1. 【LightOJ - 1027】A Dangerous Maze(概率dp,数学期望)
  2. 【CSU - 1004】Xi and Bo(并查集,裸题)
  3. 【HDU - 3466 】Proud Merchants(dp,背包问题,巧妙排序)
  4. Java 习题(面向对象)
  5. eclipse 跑maven命令_eclipse中运行maven命令没有反应,console也不出现信息
  6. java unsafe park_Java中Unsafe类详解
  7. c语言乘法表 m*(9-i),C语言做九九乘法表.doc
  8. 数组循环简单打印输出
  9. java 屏蔽邮箱_使用javamail发送邮件的时候如何阻止附件内容输出到控制台
  10. 关于“三门问题”的一些想法