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 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 you should do is to add them up.

To make the problem more complex, zhx gives you n B−base numbers
and you should also return a B−base number
to him.

What's more, zhx is so naive that he doesn't carry a number while adding. That means, his answer to 5+6 in 10−base is 1.
And he also asked you to calculate in his way.
 
Input
Multiply test cases(less than 1000).
Seek EOF as
the end of the file.

For each test, there are two integers n and B separated
by a space. (1≤n≤100, 2≤B≤36)

Then come n lines. In each line there is a B−base number(may
contain leading zeros). The digits are from 0 to 9 then
from a to z(lowercase).
The length of a number will not execeed 200.
 
Output
For each test case, output a single line indicating the answer in B−base(no
leading zero).
 
Sample Input
2 3
2
2
1 4
233
3 16
ab
bc
cd
 
Sample Output
1
233
14
 
Source
 



思路:就是不进位的大数相加啦,要注意当结果为0时输出一个0。之前我还做过一个差点儿相同的,上次注意到了,。这次竟然没注意到o(╯□╰)o.........



疑问:为何执行时间900多ms,并且还可能会T,把cstdio改为stdio.h时间就降下来了。直接变为100多ms,害的我还检查半天。。。可是这是为什么??????

搞了半天我发现使用g++环境提交的没过。而用c++环境就过啦(以后再HDU做题还是用c++环境吧。醉啦)

据说g++用scanf由于输入太慢而要开挂(难道和cin减速一个性质??)。。,。貌似是这种,以后再试试

void gn(int &x){
char c;while((c=getchar())<'0'||c>'9');x=c-'0';
while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';
}



AC代码①(100+ms。g++环境):

#include <stdio.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; char ans[205];
char t[205]; void fun(char ans[], char t[]) {
int len = strlen(t);
for(int i = 0; i < len; i++) {
ans[i] = t[len - 1 - i];
}
} void swap(char t[]) {
int len = strlen(t);
for(int i = 0; i < len / 2; i++) {
char m = t[i];
t[i] = t[len - 1 - i];
t[len - 1 - i] = m;
}
} void add(char ans[], char t[], int B) {
int t1, t2, t3;
int len = strlen(t);
for(int i = 0; i < len; i++) {
if(ans[i] <= 'z' && ans[i] >= 'a') t1 = (int)(ans[i] - 'a' + 10);
else t1 = ans[i] - '0';
if(t[i] <= 'z' && t[i] >= 'a') t2 = (int)(t[i] - 'a' + 10);
else t2 = t[i] - '0';
t3 = (t1 + t2) % B;
if(t3 >= 10) ans[i] = (char)(t3 - 10 + 'a');
else ans[i] = (char)(t3 + '0');
}
} void print(char ans[]) {
int flag = 0, p;
for(int i = 204; i >= 0; i--) {
if(ans[i] != '0') {
printf("%c", ans[i]);
flag = 1;
}
else if(ans[i] == '0' && flag) printf("0");
}
if(flag == 0) printf("0");
printf("\n");
} int main() {
int n, B;
while(scanf("%d %d", &n, &B) != EOF) {
for(int i = 0; i< 205; i++) ans[i] = '0'; scanf("%s", t);
fun(ans, t);
for(int i = 0; i < n-1; i++) {
scanf("%s", t);
swap(t);
add(ans, t, B);
}
print(ans);
}
return 0;
}

代码②(900+ms or TLE。g++环境):

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; char ans[205];
char t[205]; void fun(char ans[], char t[]) {
int len = strlen(t);
for(int i = 0; i < len; i++) {
ans[i] = t[len - 1 - i];
}
} void swap(char t[]) {
int len = strlen(t);
for(int i = 0; i < len / 2; i++) {
char m = t[i];
t[i] = t[len - 1 - i];
t[len - 1 - i] = m;
}
} void add(char ans[], char t[], int B) {
int t1, t2, t3;
int len = strlen(t);
for(int i = 0; i < len; i++) {
if(ans[i] <= 'z' && ans[i] >= 'a') t1 = (int)(ans[i] - 'a' + 10);
else t1 = ans[i] - '0';
if(t[i] <= 'z' && t[i] >= 'a') t2 = (int)(t[i] - 'a' + 10);
else t2 = t[i] - '0';
t3 = (t1 + t2) % B;
if(t3 >= 10) ans[i] = (char)(t3 - 10 + 'a');
else ans[i] = (char)(t3 + '0');
}
} void print(char ans[]) {
int flag = 0, p;
for(int i = 204; i >= 0; i--) {
if(ans[i] != '0') {
printf("%c", ans[i]);
flag = 1;
}
else if(ans[i] == '0' && flag) printf("0");
}
if(flag == 0) printf("0");
printf("\n");
} int main() {
int n, B;
while(scanf("%d %d", &n, &B) != EOF) {
for(int i = 0; i< 205; i++) ans[i] = '0'; scanf("%s", t);
fun(ans, t);
for(int i = 0; i < n-1; i++) {
scanf("%s", t);
swap(t);
add(ans, t, B);
}
print(ans);
}
return 0;
}

AC代码③:

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; #define maxn 205
char tmp[maxn][maxn], ans[maxn][maxn], ch[50];
int to[maxn]; void init() {
memset(ch, 0, sizeof(ch));
memset(to, 0, sizeof(to));
for(int i = 0; i <= 35; i++) {
if(i <= 9) ch[i] = i + '0', to[i + '0'] = i;
else ch[i] = i - 10 + 'a', to[i - 10 + 'a'] = i;
}
} int main() {
int n, B;
init();
while(~scanf("%d %d", &n, &B)) {
memset(ans, 0, sizeof(ans));
memset(tmp, 0, sizeof(tmp)); for(int i = 1; i <= n; i++) {
scanf("%s", tmp[i]);
int len = strlen(tmp[i]);
for(int j = 0; j < len; j++) {
ans[i][j] = tmp[i][len-1-j];
}
} int flag = 0;
for(int i = maxn - 1; i >= 0; i--) {
int t = 0;
for(int j = 1; j <= n; j++) {
t += to[ans[j][i]];
}
t %= B;
if(t) flag = 1;
if(flag) printf("%c", ch[t]);
}
if(!flag) printf("0");
printf("\n");
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

HDU - 5186 - zhx&#39;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 mo ...

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

    http://acm.hdu.edu.cn/showproblem.php?pid=5186 题意是分别对每一位做b进制加法,但是不要进位 模拟,注意:1 去掉前置0 2 当结果为0时输出0,而不是全 ...

  3. HDU - 5187 - zhx&#39;s contest (高速幂+高速乘)

    zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  4. HDU 5187 zhx&#39;s contest(防爆__int64 )

    Problem Description As one of the most powerful brushes, zhx is required to give his juniors n probl ...

  5. hdu 5186(模拟)

    zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  6. hdu 5188 zhx and contest [ 排序 + 背包 ]

    传送门 zhx and contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  7. hdu 5187 zhx's contest [ 找规律 + 快速幂 + 快速乘法 || Java ]

    传送门 zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  8. hdu 3966 Aragorn&#39;s Story(树链剖分+树状数组)

    pid=3966" target="_blank" style="">题目链接:hdu 3966 Aragorn's Story 题目大意:给定 ...

  9. HDU 3966 Aragorn&#39;s Story(树链剖分)

    HDU Aragorn's Story 题目链接 树抛入门裸题,这题是区间改动单点查询,于是套树状数组就OK了 代码: #include <cstdio> #include <cst ...

随机推荐

  1. hdu 2051 Bitset (java)

    问题: 之前做过类似题,但这次仍然不能解决相关问题. 字符串倒过来输:StringBuffer str=new StringBuffer(s); s=str.reverse().toString() ...

  2. cocos2d-x2.x环境搭建配置

    [安装工具] VS2012 Cocos2D-X 2.2.3 Python 2.7.8 一.运行cocos2dx中的hello world! 1.在Cocos2D-X 2.2.3目录下,点击cocos2 ...

  3. Java设计模式之认识阶段

    设计模式是什么? 设计模式(Design pattern)是一套被重复使用.多数人知晓的.经过分类编目的.代码设计经验的总结. 其本质就是继承与接口的组合应用. 为什么要用设计模? 使用设计模式是为了 ...

  4. Android该HTTP下载

    今天学习了Android开发中比較难的一个环节,就是断点续传下载,非常多人看到这个标题就感觉头大.的确,假设没有良好的逻辑思维,这块的确非常难搞明确.以下我就将自己学到的知识和一些见解写下供那些在这个 ...

  5. hdu4738(割桥)

    找人去炸边,炸完之后分成两个连通块(炸割桥) 每条边上有w个守卫,派去炸桥的人不能比守卫少 所以, 如果原本不连通,那么输出0 如果没有桥,输出-1 如果有桥没有守卫,那么是输出1,而不是0(tric ...

  6. 大并发连接的oracle在Linux下内存不足的问题的分析(转)

    最近一台装有Rhel5.3的40G内存的机器上有一个oracle数据库,数据库的SGA设置为20G,当运行业务时,一个业务高峰期时,发现swap频繁交换,CPU 100%,Load很高,基本体现为内存 ...

  7. ASP.NET之Cookie(坑爹的Response.Cookies.Remove)

    原文:ASP.NET之Cookie(坑爹的Response.Cookies.Remove) 在web开发中Cookie是必不可少的 .NET自然也有一个强大的Cookie操作类,我们用起来也非常方便, ...

  8. 【ThinkingInC++】61、非成员运算符

    非成员运算符 当操作者的左侧是不同的类时.运算符重载不可能是正确的类中. IostreamOperatorOverloading.cpp /** * 书本:[ThinkingInC++] * 功能:非 ...

  9. 【安德鲁斯】基于脚本的数据库&quot;增量更新&quot;,如果不改变,每次更新java代码、!

    思维: 1.当然,它是基于SQLiteOpenHelper.onCreate(第一个呼叫建立).onUpdate(当所谓的升级计划) 2.用"脚本"(脚本制作详细方法问度娘)做数据 ...

  10. Flex强制类型转换错误

    1.错误描写叙述 TypeError: Error #1034: 强制转换类型失败:无法将 HoleDetailInnerClass0@c2cccf1 转换为 mx.controls.listClas ...