Lonlife-ACM 1005 - Spoon Devil's RP Test(同余定理)——“玲珑杯”acm比赛-试运行赛
来源:互联网 发布:python窗口句柄 编辑:程序博客网 时间:2024/04/25 03:27
此文章可以使用目录功能哟↑(点击上方[+])
Lonlife-ACM 1005 - Spoon Devil's RP Test
Accept: 0 Submit: 0
Time Limit: 1s Memory Limit : 32MByte
Problem Description
Spoon Devil finds a way to test one person's RP: He defines 'a' = 1, 'b' = 2^2, ... 'z' = 26^2, so the value of 'abc' is 149, and the RP of 'abc' is the value of 'abc' mod 101. So the RP of 'abc' is 48.
Input
The first line is a single integer T which is the number of test cases.
Each case only contains a name, which only contains lower-case letter.
Output
For each test case, output is the RP of the name in one line.
Sample Input
spoondevil
Sample Output
Hint
Problem Idea
解题思路:
【题意】
定义'a' = 1, 'b' = 2^2, ... 'z' = 26^2
所以'abc'=149
'abc'的RP为149%101=48
现在给你一个由小写字母构成的人名
问该人名的RP值为多少
【类型】
同余定理
【分析】
由同余定理可得
①(a%m+b%m)%m≡(a+b)%m
②((a%m)*(b%m))%m≡(a*b)%m
故一个数,如567,当对4取模时,可以转化为(((5%4)*10+6)%4*10+7)%4
同理,此题就是利用这种转化,只是因为字符值不一定是一位数,故不仅仅会*10,可能还会*100,甚至*1000
【时间复杂度&&优化】
O(strlen(s))
题目链接→Lonlife-ACM 1005 - Spoon Devil's RP Test
Source Code
/*Sherlock and Watson and Adler*/#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<bitset>#include<cmath>#include<complex>#include<string>#include<algorithm>#include<iostream>#define eps 1e-9#define LL long long#define PI acos(-1.0)#define bitnum(a) __builtin_popcount(a)using namespace std;const int N = 100005;const int M = 100005;const int inf = 1000000007;const int mod = 101;char s[N];int fun(int x){ return x<10?10:x<100?100:1000;}int main(){ int t,k,i,ans; scanf("%d",&t); while(t--) { scanf("%s",s); for(ans=i=0;s[i]!='\0';i++) { k=s[i]-'a'+1; k*=k; ans=(ans*fun(k)+k)%mod; } printf("%d\n",ans); } return 0;}菜鸟成长记
- Lonlife-ACM 1005 - Spoon Devil's RP Test(同余定理)——“玲珑杯”acm比赛-试运行赛
- Lonlife-ACM 1000 - Spoon Devil's 3-D Matrix(最小生成树)——“玲珑杯”acm比赛-试运行赛
- 玲珑杯 1005 Spoon Devil's RP Test(水题)
- 玲珑学院OJ 1005 - Spoon Devil's RP Test(求余问题)
- “玲珑杯”acm比赛-试运行赛 部分题解
- 玲珑杯 1003 Spoon Devil's Diamond Mine
- 玲珑杯 1009 Spoon Devil's Bucket 矩阵优化DP
- Lonlife 1000 - Spoon Devil's 3-D Matrix
- 玲珑杯1006 Spoon Devil Love Arithmetic
- 玲珑杯 1007 Spoon Devil Love Game
- acm-求余数(同余定理)
- 玲珑学院OJ 1000 Spoon Devil's 3-D Matrix
- “玲珑杯”ACM比赛 Round #4
- 玲珑杯”ACM比赛 Round #5
- “玲珑杯”ACM比赛 Round #7
- “玲珑杯”ACM比赛 Round #7
- “玲珑杯”ACM比赛 Round #11 " ---1097
- “玲珑杯”ACM比赛 Round #11 D
- 设计模式之MVC模式
- ViewResolver
- Java8中的Reference
- 自定义View随手指滑动
- Minecraft
- Lonlife-ACM 1005 - Spoon Devil's RP Test(同余定理)——“玲珑杯”acm比赛-试运行赛
- 五种方式实现Flex页面跳转
- 欢迎使用CSDN-markdown编辑器
- 【7】TriggerListeners and JobListeners
- pygame-最易上手的2d游戏引擎
- 大数据分析进阶之python财经数据抓取
- Swift学习记录 -- 6. 字符串的基本使用
- Android基础知识--1.认识Android中的Activity组件
- Leetcode解题报告:73. Set Matrix Zeroes