codeforces 898F Hash】的更多相关文章

F. Restoring the Expression time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A correct expression of the form a+b=c was written; a, b and c are non-negative integers without leading zeros.…
898F - Restoring the Expression 思路:字符串hash,base是10,事实证明对2e64取模会T(也许ull很费时),对1e9+7取模. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ull unsigned long long #define mem(a,b) memset(a,b,sizeof(a)) ; ;…
字符串hash:  base设置为10 枚举'='可能出现的位置,从1/2处开始到大概1/3处结束,当然大概的1/3不用计算,直接到最后就行,因为本题必然有解,输出直接结束即可. 根据'='号位置,'+'最多有四种位置,因为 等式的和位数确定,有进位和不进位,左和右,最多2X2,然后剪掉j的非法位置(这里没计算除了len=3以外的j有无非法位置的可能,剪了再说) 比较需要注意的地方是等式中非个位数字不能以'0'开头,开始只以为不以'0'开头即可,WA在了 1+0=0 ,改了j后又WA了0+0=0…
PROBLEM D. Alarm Clock 题 OvO http://codeforces.com/contest/898/problem/D codeforces 898d 解 从前往后枚举,放进去后不合法就拿出来,记录拿出来的次数 中途每放进去一个数,会影响到一个区间,标记这个区间的首位(做差分,首+1,尾-1),同时维护这些标记的前缀和 #include <iostream> #include <cstring> #include <cmath> #includ…
题目链接: http://codeforces.com/problemset/problem/155/E E. Double Profiles time limit per test 3 secondsmemory limit per test 256 megabytes 问题描述 You have been offered a job in a company developing a large social network. Your first task is connected wit…
C. Registration system Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/4/C Description A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to…
E. Kefa and Watch Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/problem/E Description One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering b…
题目链接:https://codeforces.com/problemset/problem/1056/E One of Arkady's friends works at a huge radio telescope. A few decades ago the telescope has sent a signal $s$ towards a faraway galaxy. Recently they've received a response $t$ which they believe…
D. Palindrome Degree 题目连接: http://www.codeforces.com/contest/7/problem/D Description String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (k - 1)-palindromes. By definition, any string (ev…
Codeforces 25E Test E. Test Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings - input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives…
A. Search for Pretty Integers [题目链接]:http://codeforces.com/contest/872/problem/A time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given two lists of non-zero digits. Let's call an in…
E. The Classic Problem http://codeforces.com/problemset/problem/464/E 题意:给你一张无向带权图,求S-T的最短路,并输出路径.边权为2^xi.xi≤105,n≤105,m≤105. 想法:边权太大了,可以用数组按二进制存下来.带高精度跑太费事了. 观察一下,这里距离的更新:c=(a,b),用dis[a]更新dis[b] ①dis[b][c]=0,直接赋为1.只有一个数字改变. ②dis[b][c]=1,需要进位.考虑极端情况数…
题目传送门 /* hash+set:首先把各个字符串的哈希值保存在set容器里,然后对于查询的每一个字符串的每一位进行枚举 用set的find函数查找是否存在替换后的字符串,理解后并不难.另外,我想用64位的自然溢出wa了,不清楚 */ /************************************************ * Author :Running_Time * Created Time :2015-8-5 13:05:49 * File Name :D.cpp *****…
[题目链接]:http://codeforces.com/contest/514/problem/C [题意] 给你n个字符串; 然后给你m个询问;->m个字符串 对于每一个询问字符串 你需要在n个字符串里面找到和它的长度相同,且只有一个位置的字符不同的字符串; 或者告知这是不存在的; [题解] 字符串hash 因为只有3个字符 所以权值就为3^x; 找个大质数取模就好: 不够大就再大一点.. 然后对于每一位,尝试换成其他两个字母,看看存不存在; [Number Of WA] 3 [完整代码]…
http://codeforces.com/problemset/problem/757/B 题意:给出n个数,求一个最大的集合并且这个集合中的元素gcd的结果不等于1. 思路:一开始把素数表打出来,发现有9k+个数,不能暴力枚举.发现O(sqrt(n)*n)似乎可行,就枚举因子,然后出现过的因子就在Hash[]加1,最后枚举素数表里的元素,找出现次数最多的,因为那些数都可以映射在素数表里面.注意最少的ans是1. #include <cstdio> #include <algorith…
Codeforces 869E. The Untended Antiquity 题意: 在一张mxn的格子纸上,进行q次操作: 1,指定一个矩形将它用栅栏围起来. 2,撤掉一个已有的栅栏. 3,询问指定两点之间是否连通(即能否从其中一点不翻越栅栏走到另一点) 思路: 对于操作1,将给定的矩形哈希成一个数(可对点坐标进行进制哈希),对整个矩形所覆盖的点都累加上这个数: 对于操作2,则逆着把操作1的影响抵消掉: 对于操作3,看一下两点的值是否相同(相同表示他们被相同的矩形们所覆盖). 至于每次矩形内…
D. Sereja ans Anagrams time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Sereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence …
Music Mess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Description Francis really likes his music. He especially likes that song ’Zombie Nation’. Or was that the album? Or maybe the album was ’Kernkraft 4…
A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, i…
题目链接 C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy s…
D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the E…
DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In…
题意:有n个单词,每个单词长度为k,顺时针将它们写成一个圆圈串.现在知道g个长度为k的单词,是否可以从这g个单词中选择n个形成这个圆圈串?如果有多个答案,任意输出一个. 思路 可以发现,如果枚举第一个串的开始位置,由于输入的g个串,长度都为k,那么每个串的位置就固定了.那么我只要知道,在主串上那一段位置的字符串,是否存在在g个串中,然后如果每个都存在,那么就是符合的.这一部分可以用字符串hash做到O(1)判断. 复杂度的话,枚举第一个串的复杂度是k,一共需要匹配n个字符串,所以总复杂度是O(n…
题目传送门 传送门I 传送门II 传送门III 题目大意 给定将$\left \{ 0, 1, \dots, m - 1\right \}$分成了不相交的两个非空集合$A$和$B$,给定$A$,问存在多少个整数$x$满足$0\leqslant x < m$且对于任意$a\in A, b \in B$满足$a + b\not \equiv x \pmod{m}$ 容易发现满足后一个条件的充分必要条件是对于任意$a \in A$,存在$a' \in A$使得$a + a' \equiv x \pmo…
题面戳我 Solution 我们按照每个字母出现的位置进行\(hash\),比如我们记录\(a\)的位置:我们就可以把位置表示为\(0101000111\)这种形式,然后进行字符串\(hash\) 每次查询时,我们就把两个子串的每个字母的\(hash\)值,取出来,判断能否一一对应即可 为啥我的常数那么大,2700ms Code //It is coded by ning_mew on 7.23 #include<bits/stdc++.h> #define LL long long usin…
题面戳我 Solution 我们正着每次都要枚举从长到短,时间复杂度承受不了,但是我们可以发现一个规律,假设某次的答案为\(x\),那么这个字符串为\(A+X+B\)组成,无论中间的\(X\)是重叠还是空余的,我们都可以发现,这个字符串可以改成\(a+A'+X+B'+b\),所以下一次砍掉两边,这个\(A'\)中没有\(a\)与\(B'\)匹配,\(B'\)中同理没有\(b\)与\(A'\)匹配,所以公共串长度至少\(-2\). 有了上面那个性质,我们再倒着来做,我们把砍掉两边改成在两边加上两个…
题意:给你两个字符串a,b,不区分大小写,将b分成三段,重新拼接,问是否能得到A: 思路:暴力枚举两个断点,然后check的时候需要字符串hash,O(1)复杂度N*N: 题目链接:传送门 #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cmath> #include<string> #…
A - DZY Loves Hash DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert nnumbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the…
题意 给出两个字符串\(s\)和\(t\),设\(S\)为\(s\)的任意一个非空前缀,\(T\)为\(t\)的任意一个非空前缀,问\(S+T\)有多少种不同的可能. Solution 看了一圈,感觉好像就我一个人写的\(kmp+hash+\)二分. 直接算好像不是很好算?先容斥一下,不同\(=\)总方案\(-\)相同. 显然总方案为两个字符串的长度的乘积,考虑相同的情况怎么算. 相同即两组\(S\)和\(T\)不同,但\(S+T\)本质相同的情况. 这个东西怎么算呢.... (感觉看图会好理解…
D. DZY Loves Strings 题目连接: http://codeforces.com/contest/444/problem/D Description DZY loves strings, and he enjoys collecting them. In China, many people like to use strings containing their names' initials, for example: xyz, jcvb, dzy, dyh. Once DZ…