HDU 5186 zhx's submissions 模拟,细节 难度:1

http://acm.hdu.edu.cn/showproblem.php?pid=5186

题意是分别对每一位做b进制加法,但是不要进位

模拟,注意:1 去掉前置0 2 当结果为0时输出0,而不是全部去掉

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=101;
const int maxm=201;
int n,b;
char a[maxn][maxm];
int len[maxn];
char ans[maxm];
int getnum(char c){
        if(c>=‘0‘&&c<=‘9‘)return c-‘0‘;
        return c-‘a‘+10;
}
char getchar(int t){
        if(t<10)return ‘0‘+t;
        return ‘a‘+t-10;
}
void add(int ind,int num){
        int tmp=(getnum(ans[ind])+num)%b;
        ans[ind]=getchar(tmp);
}
int main(){
        while(scanf("%d%d",&n,&b)==2){
                int mxlen=0;
                for(int i=0;i<n;i++){
                        scanf("%s",a[i]);
                        len[i]=strlen(a[i]);
                        mxlen=max(mxlen,len[i]);
                }
                for(int i=0;i<mxlen;i++)ans[i]=‘0‘;
                ans[mxlen]=0;
                for(int j=1;j<=mxlen;j++){
                        for(int i=0;i<n;i++){
                                if(len[i]>=j){
                                        add(mxlen-j,getnum(a[i][len[i]-j]));
                                }
                        }
                }
                int ind;
                for(ind =0;ans[ind]==‘0‘&&ind<mxlen-1;ind++){}
                printf("%s\n",ans+ind);

        }
        return 0;
}

  

HDU 5186 zhx's submissions 模拟,细节 难度:1

时间: 2024-10-18 14:50:50

HDU 5186 zhx's submissions 模拟,细节 难度:1的相关文章

HDU 5186 zhx&#39;s submissions (进制转换)

Problem Description As one of the most powerful brushes, zhx submits a lot of code on many oj and most of them got AC. One day, zhx wants to count how many submissions he made on n ojs. He knows that on the ith oj, he made ai submissions. And what yo

HDU - 5186 - zhx&#39;s submissions (大数高精度)

zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 540    Accepted Submission(s): 146 Problem Description As one of the most powerful brushes, zhx submits a lot of code on many o

杭电 HDU ACM 5186 zhx&#39;s submissions

zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1892    Accepted Submission(s): 507 Problem Description As one of the most powerful brushes, zhx submits a lot of code on many

HDU - 5187 zhx&#39;s contest(快速幂+快速乘法)

作为史上最强的刷子之一,zhx的老师让他给学弟(mei)们出n道题.zhx认为第i道题的难度就是i.他想要让这些题目排列起来很漂亮. zhx认为一个漂亮的序列{ai}下列两个条件均需满足. 1:a1..ai是单调递减或者单调递增的. 2:ai..an是单调递减或者单调递增的. 他想你告诉他有多少种排列是漂亮的.因为答案很大,所以只需要输出答案模p之后的值. Input Multiply test cases(less than 10001000). Seek EOF as the end of

Hdu 3887树状数组+模拟栈

题目链接 Counting Offspring Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1757    Accepted Submission(s): 582 Problem Description You are given a tree, it’s root is p, and the node is numbered fr

hdu 4891 The Great Pan(模拟)

题目链接:hdu 4891 The Great Pan 题目大意:给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn+1), si表示连续的空格数. 2.{}中间,即 | 的个数+1. 解题思路:模拟. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1<<22

HDU 4930 Fighting the Landlords 模拟

_(:зゝ∠)_ 4带2居然不是炸弹,, #include <algorithm> #include <cctype> #include <cassert> #include <cstdio> #include <cstring> #include <climits> #include <vector> #include<iostream> using namespace std; #define N 18 #

hdu 1316 How Many Fibs? (模拟高精度)

题目大意: 问[s,e]之间有多少个 斐波那契数. 思路分析: 直接模拟高精度字符串的加法和大小的比较. 注意wa点再 s 可以从 0 开始 那么要在判断输入结束的时候注意一下. #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; struct node { char str[111]; int len; void

HDU 4831 Scenic Popularity 暴力模拟

Scenic Popularity Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 340    Accepted Submission(s): 110 Problem Description 临近节日,度度熊们最近计划到室外游玩公园,公园内部包括了很多的旅游景点区和休息区,由于旅游景点很热门,导致景点区和休息区都聚集了很多人.所以度度熊