FZU 2111 Min Number

这题 没有想到 是 贪心的算法.

所以和队友两个人一直卡在这里.

一直用其中一个队友的方法,卡了一小时多,回来以后继续写,卡在另外一个地方.

感觉就是自己的思路太狭窄了...可能因为不是很认真吧..

或许比赛的时候就不一样了..

福州OJ的测试数据太弱了..就不写优化了.

优化就是拿到最小值,接下来就不比了..

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 #define maxn 1005
 6 char c[maxn];
 7 int main()
 8 {
 9     int T,m,len,p,mi,t;
10     //freopen("2111.txt","r",stdin);
11     scanf("%d",&T);
12     while(T--)
13     {
14         scanf("%s%d",c,&m);
15         len=strlen(c);
16         for(int i=0;i<len&&m;i++)
17         {
18             p=-1;mi=c[i];
19            for(int j=i;j<len;j++)
20             if(mi>c[j]&&(c[j]!=‘0‘||i))  //i=0 不能换
21             {
22                 mi=c[j];
23                 p=j;
24             }
25             if(p!=-1)
26            {
27             t=c[p];
28             c[p]=c[i];
29             c[i]=t;
30             m--;
31            }
32         }
33         printf("%s\n",c);
34     }
35     return 0;
36 }
37         
时间: 2024-08-17 00:21:13

FZU 2111 Min Number的相关文章

FZU OJ 2111 Min Number (贪心)

Problem 2111 Min Number Accept: 586    Submit: 1139 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Now you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choo

foj 2111 Problem 2111 Min Number

Problem 2111 Min Number Accept: 1025    Submit: 2022Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description Now you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choos

FZU Problem 2111 Min Number (数学啊 )

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2111 Problem Description Now you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choose 2 integers i and j, such that: i!=j, 1≤i<j≤|n|, her

Min Number 贪心,把最小的数放在最前

题目链接 Problem 2111 Min Number Accept: 499    Submit: 949 Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description Now you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to c

FZU 2102 Solve equation(水,进制转化)&amp;&amp; FZU 2111(贪心,交换使数字最小)

C Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice FZU 2102 Description You are given two positive integers A and B in Base C. For the equation: A=k*B+d We know there always existing many non-negativ

fzu 2109 Mountain Number 数位DP

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2109 题意: 如果一个>0的整数x,满足a[2*i+1] >= a[2*i]和a[2*i+2],则这个数为Mountain Number. 给出L, R,求区间[L, R]有多少个Mountain Number. 思路: 数位DP,判断当前是偶数位还是奇数位(从0开始),如果是偶数位,那么它要比前一个数的值小, 如果是奇数位,那么它要比前一个数的值大. 1 #include <iostream>

FZU Problem 1853 Number Deletion

Problem 1853 Number Deletion Accept: 80    Submit: 239 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Given you one n-digital positive integer a,After removing any of them k( k < n) digits, the remaining figures form a new posi

&quot;高教社杯&quot;第三届福建省大学生程序设计竞赛

 A.Problem 2102 Solve equation Accept: 1032    Submit: 2471 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description You are given two positive integers A and B in Base C. For the equation: A=k*B+d We know there always existing many non-

ExtJS学习-----------Ext.Number,ExtJS对javascript中的Number的扩展

关于ExtJS对javascript中的Number的扩展,可以参考其帮助文档,文档下载地址:http://download.csdn.net/detail/z1137730824/7748893 下面对其中的部分方法进行介绍: (1)constrain constrain( Number number, Number min, Number max ) : Number 检查给定的数值是否在约束的范围内. If the number is already within the 如果再范围内就返