ZOJ:1164 Software CRC
来源:互联网 发布:元数据系统 编辑:程序博客网 时间:2024/06/10 11:37
此题在ZOJ上AC,UVa上一直TLE,不知为何。
其中res这个变量要用longlong,用int会WA,虽然我感觉int足够。
这个题主要是用到了一个进制转化的问题。就像十进制里面每位相差10倍关系,二进制则是两倍关系。懂了这点就好做了。取余的时候二进制可以转化成十进制来算。最后枚举答案看是否能整除就行了。
一开始以为CRC是两块,30000*30000妥超时,后来才发现它是一个数。
#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <algorithm>#define MAXN 1024#define INF 2139062143#define ll long longusing namespace std;const int key=34943;char str[MAXN+5];int main(){ while(gets(str)) { if(!strcmp(str,"#")) break; ll res=0; int L=strlen(str); for(int i=0; i<L; ++i) { res=res*256+str[i]; res=res%key; } res=res*65536; int ans=0; for(int i=0; i<key; ++i) if((res+i)%key==0) { ans=i; break; } sprintf(str,"%04X",ans); putchar(str[0]); putchar(str[1]); putchar(' '); putchar(str[2]); putchar(str[3]); putchar('\n'); } return 0;}
后来发现暴力那块是没必要写的,改掉之后特判了空行,UVa上AC。
#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <algorithm>#define MAXN 1024#define INF 2139062143#define ll long longusing namespace std;const int key=34943;char str[MAXN+5];int main(){ while(gets(str)) { if(!strcmp(str,"#")) break; if(!strlen(str)) { puts("00 00"); continue; } ll res=0; int L=strlen(str); for(int i=0; i<L; ++i) { res=res*256+str[i]; res=res%key; } res=res*65536; res=res%key; int ans=key-res; sprintf(str,"%04X",ans); putchar(str[0]); putchar(str[1]); putchar(' '); putchar(str[2]); putchar(str[3]); putchar('\n'); } return 0;}
0 0
- ZOJ:1164 Software CRC
- Software CRC
- uva 128 - Software CRC
- UVa 128 - Software CRC
- 128 - Software CRC
- UVaOJ128 - Software CRC
- UVa 128 - Software CRC
- UVA - 128 Software CRC
- UVA 128 - Software CRC
- UVA128- Software CRC
- UVa 128 - Software CRC
- UVA - 128 Software CRC
- uva 128 Software CRC
- UVa 128 Software CRC (模计算&CRC循环冗余校验码)
- 128 - Software CRC//大数求余
- UVa 128 Software CRC / 进制转换
- UVA128 - Software CRC(大数取模)
- Software CRC - UVa 128 取模
- 黑马程序员_java概述
- 10 000小时的标准----是否有先天的才能
- 疑问
- 对多目标粒子群算法MOPSO的理解
- The constructor AlertDialog.Builder(***) is undefined
- ZOJ:1164 Software CRC
- 黑马程序员------------------反射
- jsoncpp使用方法
- Core Data Relationship Delete Rule
- RelationsShip Delete Rule
- 冒泡法排序
- 第五篇:风起于青萍之末-电源管理请求案例分析(上)
- linux操作系统
- Servlet实例创建时刻