BestCoder 2nd Anniversary

http://acm.hdu.edu.cn/search.php?field=problem&key=BestCoder+2nd+Anniversary&source=1&searchmode=source

A

取最小的非零数,再相加

 1 // #pragma comment(linker, "/STACK:102c000000,102c000000")
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <sstream>
 6 #include <string>
 7 #include <algorithm>
 8 #include <list>
 9 #include <map>
10 #include <vector>
11 #include <queue>
12 #include <stack>
13 #include <cmath>
14 #include <cstdlib>
15 // #include <conio.h>
16 using namespace std;
17 #define clc(a,b) memset(a,b,sizeof(a))
18 #define inf 0x3f3f3f3f
19 #define lson l,mid,rt<<1
20 #define rson mid+1,r,rt<<1|1
21 const int N = 1e7+10;
22 const int MOD = 1e9+7;
23 #define LL long long
24 #define mi() (l+r)>>1
25 double const pi = acos(-1);
26
27 void fre() {
28     freopen("in.txt","r",stdin);
29 }
30
31 // inline int r() {
32 //     int x=0,f=1;char ch=getchar();
33 //     while(ch>‘9‘||ch<‘0‘) {if(ch==‘-‘) f=-1;ch=getchar();}
34 //     while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘;ch=getchar();}return x*f;
35 // }
36
37 int a[N];
38 int main(){
39     int T;
40     scanf("%d",&T);
41     while(T--){
42         string s;
43         cin>>s;
44         int len=s.length();
45         int k=0;
46         int minn=inf;
47         int cnt=0;
48         for(int i=0;i<len;i++){
49              a[k++]=s[i]-‘0‘;
50              if(minn>s[i]-‘0‘&&s[i]-‘0‘!=0){
51                 minn=s[i]-‘0‘;
52              }
53              if(s[i]-‘0‘!=0){
54                 cnt++;
55              }
56         }
57         // cout<<minn<<endl;
58         if(cnt<2){
59             printf("Uncertain\n");
60             continue;
61         }
62         sort(a,a+k);
63         int pos=lower_bound(a,a+k,minn)-a;
64         // cout<<pos<<endl;
65         // if(pos==0)
66         //     pos++;
67         // cout<<k<<endl;
68         for(int i=pos;i<k-1;i++){
69             a[i]=a[i+1];
70         }
71         // cout<<a[0]<<a[1]<<endl;
72         int b=0;
73         k-=2;
74         for(int i=0;i<=k;i++){
75             a[i]=(a[i]+minn+b)%10;
76             b=(a[i]+minn+b)/10;
77             minn=0;
78         }
79         // cout<<a[0]<<a[1]<<endl;
80         if(b){
81             a[++k]=b;
82         }
83         for(int i=k;i>=0;i--){
84             printf("%d",a[i]);
85         }
86         printf("\n");
87     }
88     return 0;
89 }

时间: 2024-12-24 23:06:37

BestCoder 2nd Anniversary的相关文章

BestCoder 2nd Anniversary的前两题

Oracle Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 79    Accepted Submission(s): 41 Problem Description There is once a king and queen, rulers of an unnamed city, who have three daughters

HDU 5720 Wool BestCoder 2nd Anniversary (区间覆盖)

Wool Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 686    Accepted Submission(s): 192 Problem Description At dawn, Venus sets a second task for Psyche. She is to cross a river and fetch gol

HDU 5719 BestCoder 2nd Anniversary Arrange (DP)

Arrange Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 558    Accepted Submission(s): 198 Problem Description Accidentally, Cupid, god of desire has hurt himself with his own dart and fallen

HDU 5721 Palace BestCoder 2nd Anniversary (平面最近点对)

Palace Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 465    Accepted Submission(s): 118 Problem Description The last trial Venus imposes on Psyche is a quest to the underworld. She is to ta

hdu 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5719 题意:一个数列为1~N的排列,给定mn[1...n]和mx[1...n],问有符合的排列数为多少?如果不存在,输出0: 思路: 有解的几种条件: 1. mn , mx 变化单调: 2. mn,mx 不能同时变化: 3. 一个位置可选的个数>0; 当解存在时,递推出每次可选择的个数,num += mx[i] - mx[i-1] + mn[i-1] - mn[i] - 1; 即可: 坑:开始想成了

BestCoder 2nd Anniversary 1005&amp;Hdu 5722 -Jewelry

题意:问有多少个合法区间. 分析:对于[l,r],枚举右区间r,获取合法的l的区间.当增加一个元素Ai,原来合法的区间就会变不合法,要删掉,同时又会新增一个合法的区间,要插入. 例如,当x=2,对于元素 Ai其出现的位置为:1 2 3, 当新增位置4又出现Ai时,那么原来[1+1,2]的区间不合法,删掉.然后区间[2+1,3],插入. /************************************************ Author :DarkTong Created Time :

BestCoder 2nd Anniversary 1004&amp;Hdu 5721 Palace

题意:给定n个点,对于每次消失一个点,问剩下的点中的最短距离是多少,然后所有最短距离的和. 分析:1.模版题,然而没模版的我码了半天. 2.(1)只要不删掉与最短距离相关的两个点,那么最短距离不变. (2)若与最短距离的点相关,删掉点后,重新算一遍. /************************************************ Author :DarkTong Created Time :2016/7/18 14:01:14 File Name :d.cpp *******

BestCoder 2nd Anniversary 1001 Oracle

找到最小的非零数字拆开来相加. 高精度. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 using namespace std; 7 #define LL long long 8 char s[10000005]; 9 int a[10000005],b[10000005]; 10

【HDU5721 BestCoder 2nd AnniversaryD】【平面最近点对 分治写法+KD-tree写法】Palace 平面最近点对

Palace Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 260    Accepted Submission(s): 72 Problem Description The last trial Venus imposes on Psyche is a quest to the underworld. She is to tak