Codeforces 760A Petr and a calendar】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/760/A 题意:日历需要多少列. #include <bits/stdc++.h> using namespace std; ] = {,,,,,,,,,,,}; int main() { int m,d; scanf("%d%d",&m,&d); ]; ; day = day - (-d+); ) ans+=(day/+); ); printf("%d\…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequ…
题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (online version))成功AC的题目(n ≤ 106),解题的突破口是:Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number.…
题目链接:http://codeforces.com/problemset/problem/113/B 题目大意: 多组数据每组给定3个字符串T,Sbeg,Sed,求字符串T中有多少子串是以Sbeg开头,Sed结尾的 分析: 难点在哈希函数的编写,如果直接存string会爆内存,不能用STL自带哈希函数,用了会Wa. 代码如下: #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i &l…
题目连接: Petr and Permutations 题意:给出一个1到n的序列,Petr打乱了3n次,Um_nik打乱了7n+1次,现在给出被打乱后的序列,求是谁打乱的. 题解:因为给出了一个3*n和一个7*n+1,发现这两个当一个为奇数另一个一定为偶数,所以可以联想和奇偶性质有关.但是这里面要算最短几步能把当前的序列变成1-n.这里我算错~~顺便学了一下如何将置换序列复原. #include<bits/stdc++.h> using namespace std; typedef pair…
题意:初始有一个序列[1,2,...N],一次操作可以将任意两个位置的值互换,Petr做3*n次操作:Alxe做7*n+1次操作.给出最后生成的新序列,问是由谁操作得到的. 分析:一个序列的状态可以归为:由原序列操作奇数次得到(简称奇序列):和操作偶数次(偶序列)得到.显然奇序列中,逆序对的个数为奇数:偶序列中,逆序对的个数为偶.当n为奇数时,3*n为奇,7*n+1为偶:n为偶数时正好相反. 用树状数组或归并排序求逆序对即可. #include<iostream> #include<st…
这题真的只能靠直觉了,我没法给出详细证明. 解题思路: 1.交换3n次或者7n+1次,一定会出现一个为奇数,另一个为偶数. 2.用最朴素的方法,将n个数字归位,计算交换次数. 3.判断交换次数是否与3n的奇偶性相同,相同输出Petr: 不相同则一定与7n+1的奇偶性相同,输出Um_nik. 代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; ]; ]; int main(){ ios::sync_wit…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given names of two days of the week. Please, determine whether it is possible that during some non-leap year the first day of some month…
Description\text{Description}Description Given an array a[], swap random 2 number of them for 3n or (7n+1) times.\text{Given an array }a[],\text{ swap random 2 number of them for }3n\text{ or }(7n+1)\text{ times.}Given an array a[], swap random 2 num…
应该算是远古时期的一道题了吧,不过感觉挺经典的. 题意是给出三一个字符串s,a,b,求以a开头b结尾的本质不同的字符串数. 由于n不算大,用hash就可以搞,不过这道题是存在复杂度$O(nlogn)$的做法的. 由于要求本质不同,所以可以考虑使用后缀数组来不重复地枚举字符串. 首先用两个不同的其他字符将s,a,b拼起来求后缀数组,这样就可以知道任意两个后缀的lcp了.然后将s中所有b出现的末尾位置置1,求个后缀和suf.将s中所有后缀按名次从小到大存到一个vector里.对于s中的每个后缀,设其…