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
  1. 2 3
  2. 2
  3. 2
  4. 1 4
  5. 233
  6. 3 16
  7. ab
  8. bc
  9. cd
 
Sample Output
  1. 1
  2. 233
  3. 14
 
Source
 



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



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

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

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

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



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

  1. #include <stdio.h>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <cmath>
  6. using namespace std;
  7.  
  8. char ans[205];
  9. char t[205];
  10.  
  11. void fun(char ans[], char t[]) {
  12. int len = strlen(t);
  13. for(int i = 0; i < len; i++) {
  14. ans[i] = t[len - 1 - i];
  15. }
  16. }
  17.  
  18. void swap(char t[]) {
  19. int len = strlen(t);
  20. for(int i = 0; i < len / 2; i++) {
  21. char m = t[i];
  22. t[i] = t[len - 1 - i];
  23. t[len - 1 - i] = m;
  24. }
  25. }
  26.  
  27. void add(char ans[], char t[], int B) {
  28. int t1, t2, t3;
  29. int len = strlen(t);
  30. for(int i = 0; i < len; i++) {
  31. if(ans[i] <= 'z' && ans[i] >= 'a') t1 = (int)(ans[i] - 'a' + 10);
  32. else t1 = ans[i] - '0';
  33. if(t[i] <= 'z' && t[i] >= 'a') t2 = (int)(t[i] - 'a' + 10);
  34. else t2 = t[i] - '0';
  35. t3 = (t1 + t2) % B;
  36. if(t3 >= 10) ans[i] = (char)(t3 - 10 + 'a');
  37. else ans[i] = (char)(t3 + '0');
  38. }
  39. }
  40.  
  41. void print(char ans[]) {
  42. int flag = 0, p;
  43. for(int i = 204; i >= 0; i--) {
  44. if(ans[i] != '0') {
  45. printf("%c", ans[i]);
  46. flag = 1;
  47. }
  48. else if(ans[i] == '0' && flag) printf("0");
  49. }
  50. if(flag == 0) printf("0");
  51. printf("\n");
  52. }
  53.  
  54. int main() {
  55. int n, B;
  56. while(scanf("%d %d", &n, &B) != EOF) {
  57. for(int i = 0; i< 205; i++) ans[i] = '0';
  58.  
  59. scanf("%s", t);
  60. fun(ans, t);
  61. for(int i = 0; i < n-1; i++) {
  62. scanf("%s", t);
  63. swap(t);
  64. add(ans, t, B);
  65. }
  66. print(ans);
  67. }
  68. return 0;
  69. }

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

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <cmath>
  6. using namespace std;
  7.  
  8. char ans[205];
  9. char t[205];
  10.  
  11. void fun(char ans[], char t[]) {
  12. int len = strlen(t);
  13. for(int i = 0; i < len; i++) {
  14. ans[i] = t[len - 1 - i];
  15. }
  16. }
  17.  
  18. void swap(char t[]) {
  19. int len = strlen(t);
  20. for(int i = 0; i < len / 2; i++) {
  21. char m = t[i];
  22. t[i] = t[len - 1 - i];
  23. t[len - 1 - i] = m;
  24. }
  25. }
  26.  
  27. void add(char ans[], char t[], int B) {
  28. int t1, t2, t3;
  29. int len = strlen(t);
  30. for(int i = 0; i < len; i++) {
  31. if(ans[i] <= 'z' && ans[i] >= 'a') t1 = (int)(ans[i] - 'a' + 10);
  32. else t1 = ans[i] - '0';
  33. if(t[i] <= 'z' && t[i] >= 'a') t2 = (int)(t[i] - 'a' + 10);
  34. else t2 = t[i] - '0';
  35. t3 = (t1 + t2) % B;
  36. if(t3 >= 10) ans[i] = (char)(t3 - 10 + 'a');
  37. else ans[i] = (char)(t3 + '0');
  38. }
  39. }
  40.  
  41. void print(char ans[]) {
  42. int flag = 0, p;
  43. for(int i = 204; i >= 0; i--) {
  44. if(ans[i] != '0') {
  45. printf("%c", ans[i]);
  46. flag = 1;
  47. }
  48. else if(ans[i] == '0' && flag) printf("0");
  49. }
  50. if(flag == 0) printf("0");
  51. printf("\n");
  52. }
  53.  
  54. int main() {
  55. int n, B;
  56. while(scanf("%d %d", &n, &B) != EOF) {
  57. for(int i = 0; i< 205; i++) ans[i] = '0';
  58.  
  59. scanf("%s", t);
  60. fun(ans, t);
  61. for(int i = 0; i < n-1; i++) {
  62. scanf("%s", t);
  63. swap(t);
  64. add(ans, t, B);
  65. }
  66. print(ans);
  67. }
  68. return 0;
  69. }

AC代码③:

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. #define maxn 205
  7. char tmp[maxn][maxn], ans[maxn][maxn], ch[50];
  8. int to[maxn];
  9.  
  10. void init() {
  11. memset(ch, 0, sizeof(ch));
  12. memset(to, 0, sizeof(to));
  13. for(int i = 0; i <= 35; i++) {
  14. if(i <= 9) ch[i] = i + '0', to[i + '0'] = i;
  15. else ch[i] = i - 10 + 'a', to[i - 10 + 'a'] = i;
  16. }
  17. }
  18.  
  19. int main() {
  20. int n, B;
  21. init();
  22. while(~scanf("%d %d", &n, &B)) {
  23. memset(ans, 0, sizeof(ans));
  24. memset(tmp, 0, sizeof(tmp));
  25.  
  26. for(int i = 1; i <= n; i++) {
  27. scanf("%s", tmp[i]);
  28. int len = strlen(tmp[i]);
  29. for(int j = 0; j < len; j++) {
  30. ans[i][j] = tmp[i][len-1-j];
  31. }
  32. }
  33.  
  34. int flag = 0;
  35. for(int i = maxn - 1; i >= 0; i--) {
  36. int t = 0;
  37. for(int j = 1; j <= n; j++) {
  38. t += to[ans[j][i]];
  39. }
  40. t %= B;
  41. if(t) flag = 1;
  42. if(flag) printf("%c", ch[t]);
  43. }
  44. if(!flag) printf("0");
  45. printf("\n");
  46. }
  47. return 0;
  48. }

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

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. 修ecshop品牌筛选以LOGO图片形式显示

    如何实现商品列表页属性筛选区品牌筛选以LOGO形式展示,最模板总结ecshop/'>ecshop教程入下: 1.修改 category.php 文件,将(大概215行) $sql = " ...

  2. const使用摘要

    const在四种方案如以下: int b = 500; const int *a = &b; ①(底层const) int const *a = &b; ②(底层const) int ...

  3. Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: &#39;L

    1.错误叙述性说明 [ERROR:]2015-06-08 09:49:42,523 [异常拦截] org.hibernate.exception.DataException: error execut ...

  4. erlang如何有效地监视大量的并发连接

    阅读erlang一些开源web框架RabbitMQ.Ranch,他们使用多个进程在同一时间accept一socket.以这样的方式,使socketport监控共享很多其他的机会调度工作,但,在erla ...

  5. WCF配置文件

    因为要上传较大的图片,WCF传递数组的默认的最大数组16KB就不够了.以下讲解配置内容. 服务端配置 这里一个WCF项目中有1个服务,配置文件如下(位于system.serviceModel标签中): ...

  6. Cocos2d-x 3.2 Lua演示样例 XMLHttpRequestTest(Http网络请求)

    Cocos2d-x 3.2 Lua演示样例 XMLHttpRequestTest(Http网络请求)     本篇博客介绍Cocos2d-x 3.2Lua演示样例中的XMLHttpRequestTes ...

  7. HDU4960Another OCD Patient(间隙dp,后座DP)

    Another OCD Patient Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Ot ...

  8. mac开启22port

    mac开启22port 选择System prefrence -> sharing , 将remote login打开 測试是否打开 import socket s = socket.socke ...

  9. 全文检索引擎Solr 指南

    全文检索引擎Solr系列:第一篇:http://t.cn/RP004gl.第二篇:http://t.cn/RPHDjk7 .第三篇:http://t.cn/RPuJt3T

  10. dm8148 jpeg编解码器测试

    测试过程: 1)于A8将jpeg传送到videoM3解码,然后,videoM3编码.在编译jpeg图像传输到A8,主要是测试jpeg编码的图像需要多少时间: 1000w像素:  编码时间:43ms. ...