semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from the Petrozaporksk training camp. There, he learned a lot of things: how to boil a cob, how to scratch his belly using his keyboard, etc... He almost r…
algoritm.in / algoritm.out Even though he isn't a student of computer science, Por Costel the pig has started to study Graph Theory. Today he's learning about Bellman-Ford, an algorithm that calculates the minimum cost path from a source node (for in…
semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from the Petrozaporksk training camp. There, he learned a lot of things: how to boil a cob, how to scratch his belly using his keyboard, etc... He almost r…
perechi3.in / perechi3.out We don't know how Por Costel the pig arrived at FMI's dance party. All we know is that he did. The dance floor is hot because Por Costel broke the air conditioner. On the dance floor, the boys and girls are clumsy. There ar…
meciul.in / meciul.out Oberyn Martell and Gregor Clegane are dueling in a trial by combat. The fight is extremely important, as the life of Tyrion Lannister is on the line. Oberyn and Gregor are measuring their skill in combat the only way the two be…
azerah.in / azerah.out Por Costel the Pig has received a royal invitation to the palace of the Egg-Emperor of Programming, Azerah. Azerah had heard of the renowned pig and wanted to see him with his own eyes. Por Costel, having arrived at the palace,…
裸题. 看之前的模版讲解吧,这里不再赘述了. #include<cstdio> #include<cstring> using namespace std; int fa[100010]; bool rel[100010]; int n,m,T; int findroot(int x){ if(x==fa[x]){ return x; } int Fa=findroot(fa[x]); if(rel[x]==0 && rel[fa[x]]==0){ rel[x]=0…
Por Costel and Azerah Descriptions 给你n个数 问你,有多少个子序列 的和是偶数 Example Input 233 10 124 2 Output 33 题目链接 https://vjudge.net/problem/Gym-100923A   恶心死了   freopen("azerah.in","r",stdin); freopen("azerah.out","w",stdout); 必…
Por Costel and the Pairs Descriptions 有T组测试样例 有n个男的,n个女的,第i个人都有为当前一个大小为i的懒惰值,当一男一女懒惰值的乘积<=n他们就就可以一起跳舞,请问有多少种组合可能: Example Input 1114510100991664495048 Output 18102748247350280201207198 题目链接 https://vjudge.net/problem/Gym-100923I   求n/1+n/2+...+n/n,除法…
题目链接 洛谷P4240 题解 式子不难推,分块打表真的没想到 首先考虑如何拆开\(\varphi(ij)\) 考虑公式 \[\varphi(ij) = ij\prod\limits_{p | ij}\frac{p - 1}{p}\] 而 \[ \begin{aligned} \varphi(i)\varphi(j) &= i\prod\limits_{p | i}\frac{p - 1}{p} j \prod\limits_{p | j}\frac{p - 1}{p} \\ \varphi(i…
题目链接 掌握了分块打表法了.原来以前一直想错了... 块的大小\(size=\sqrt n\),每隔\(size\)个数打一个表,还要在\(0\text{~}size-1\)每个数打一个表. 然后就可以做到\(O(1)\)查询了. 比如要求\(A^{n}\),只需要算出\(biao[n/size]*pow[n\mod size]\)就好了. 然后我是看题解用了通项公式..事实上套个矩阵也没有影响. #include <cstdio> #include <cmath> #defin…
验证一个数是不是优美的:设数位之和为sum,若sum mod 2 != 0,则不优美.否则考虑枚举这个数的每一位,将之前所有位任意相加产生的所有 数字和 和 当前位 的和塞到集合里,最终判断集合中是否存在sum/2即可,若暴力,复杂度是1+2+4+...,无法承受,所以可以压位. 然后对10^9分块,暴力处理每个块内的答案,然后打个表,对零散的部分暴力即可. #include<cstdio> using namespace std; const int table[]={0,376413,83…
/* 打不了那么大的表,所以只记录分块的信息即可 */ #include<bits/stdc++.h> using namespace std; #define maxn 1000005 double arr[maxn]; void init(){ arr[]=; ; ;i<maxn*;i++){ tmp=tmp+1.0/i; ==)arr[i/]=tmp; } } int main(){ init(); ; cin>>T; while(T--){ cin>>n;…
[BZOJ3798]特殊的质数 Description 求[A,B]之间的质数个数,并且满足X=Q^2+P^2,P,Q是正整数. Input 第一行输入A,B Output 输出有多少组P,Q满足条件 Sample Input 6 66 Sample Output 7 HINT 1<=A<=B<=3*10^8 题解:还有什么比表打错了更让人欲哭无泪的~ 注意一下几点: 1.分块不能太小,10^5很稳,再小有可能装不下了 2.2=1*1+1*1,也算~ 3.不要把x=i*i+0*0这样的算…
题目 对于任意一个至少两位的正整数n,按如下方式定义magic(n):将n按十进制顺序写下来,依次对相邻两个数写下差的绝对值.这样,得到了一个新数,去掉前导0,则定义为magic(n).若n为一位数,则magic(n)=n. 例如:magic(5913)=482,magic(1198)=081=81,magic(666)=00=0. 对任意一个数n,序列n,magic(n),magic(magic(n)),-迟早会变成一个一位数.最后的这个值称为数n的magic指纹. 例如,对于n=5913,我…
[题目描述] Description 神犇最近闲来无事,于是就思考哲学,研究数字之美.在神犇看来,如果一个数的各位能够被分成两个集合,而且这两个集合里的数的和相等,那么这个数就是优美的(具体原因就只有神犇才知道了).现在神犇在思考另一个问题,在区间[a,b]中有多少个数是优美的?这个问题对于神犇来说很简单,相信对于你来说也不难. Input 输入只有一行,包含两个整数a和b. Output 输出只有一行,包含一个整数,代表区间[a,b]中优美的数的个数. Sample Input 1 11 Sa…
正题 题目链接:https://www.luogu.com.cn/problem/P3793 题目大意 给出\(n\)个数字的一个序列\(m\)次询问区间最大值 保证数据随机 \(1\leq n,m\leq 2\times 10^7\) 解题思路 使用\(ST\)表可以做到\(O(1)\)询问,但是预处理的时空复杂度都是\(O(n\log n)\),且自带大常数导致过不了. 如何加快预处理的时间,(因为是lxl的题目所以)考虑使用分块.每次询问可以分为整块的部分和不是整块的零散部分. 去掉没有跨…
首先题目等价于求出满足运行二分程序后最后r=k的排列种数. 显然对于这样的二分程序,起作用的只有mid点,mid处的值决定了接下来要递归的子区间. 于是可以一遍二分求出有多少个mid点处的值<=m,有多少个mid点处的值>m,不妨设为x和y, 那么由组合数学可以推出最后的答案是 C(x,m)*C(y,n-m)*(n-x-y)!%MOD. 由于x和y很小,所以前面两个组合数可以暴力算出来.而后面的阶乘显然是不能直接求的. 打表的话n<=1e9,显然会MLE,于是把n分成100块,预处理出n…
思路: 这题思路真是奇妙 先跑个暴力 每隔1e5打个表 块内暴力 打表程序: (开O3 15秒就跑完了) //By SiriusRen #include <bits/stdc++.h> using namespace std; ; bitset<N+>vis; ],sum[N+],s[]; int main(){ ;i<=N;i++){ if(!vis[i])prime[++tot]=i; ;i*prime[j]<=N&&j<=tot;j++){…
题目链接:http://codeforces.com/gym/100923/problem/H 分析:并查集,用enemy储存x的敌人,用weight储存权重决定根节点 需用scanf和puts输入输出否则会爆 1 #include<iostream> 2 #include<sstream> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<string> 6 #include<cstrin…
题目链接:http://codeforces.com/gym/100923/problem/L 分析:题目要求序列首尾相同,在此基础上的字典序第k个:因为只存在a,b所以我们把它等效成0和1的话,字典序k也就是二进制下的k,将其最后一位与序列头部相同即可 1 #include<iostream> 2 #include<sstream> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<string>…
#include<cstdio> using namespace std; #define BN 380000 const int table[]={0,185815,378154,561654,744350,886427,1075474,1310828,1513089,1705514,1867434,1971454,2248548,2469454,2649024,2835571,2981002,3136779,3301075,3435869,3558911,3662068,3715857,4…
#include<cstdio> using namespace std; #define BN 380000 const int table[]={0,79595,158824,202174,246052,316791,359819,411663,482117,517179,574651,649803,674577,742659,818419,831971,907450,978470,1000268,1073090,1146729,1168243,1236041,1304374,132588…
块大小为10^5. #include<cstdio> using namespace std; const int table[] = {0, 4784, 8978, 12981, 16901, 20732, 24523, 28249, 31916, 35585, 39176, 42818, 46430, 49962, 53516, 57023, 60523, 64040, 67489, 70985, 74417, 77879, 81285, 84679, 88055, 91433, 9487…
题意:简化一下 就是解N个 系数矩阵一样 等式右边列矩阵不一样的方程组 题解:系数矩阵一样 为什么我却毫无办法???? 其实只要把等式右边的矩阵都排在后面就好了啊 就变成解一个N x 2N的方程组了 ... #include <bits/stdc++.h> using namespace std; const double eps = 1e-9; int n; double a[205][405]; void gauss() { int now = 1, to; for(int i = 1;…
// 7.19-7.29 东北大学秦皇岛校区十天训练营,题目都挂在了Vjudge上.训练期间比较忙,没空更博总结,回来继续补题消化. Day1 这天授课主题是简单图论,节奏挺好,wls两小时理完图论里的基本知识点. 下午的赛题就偏入门了(简单图论无疑),只涉及到最短路问题和简单的搜索以及一些奇怪的技巧.(差分约束呢?最小生成树呢?强连通分量呢?) A - Jzzhu and Cities (补) 把火车线路加上跑Dijkstra就好了,标记火车线路,相等时也要push.在最短路上的火车线路不能被…
度度熊保护村庄 Accepts: 13 Submissions: 488 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description 哗啦啦村袭击了喵哈哈村! 度度熊为了拯救喵哈哈村,带着自己的伙伴去救援喵哈哈村去了!度度熊与伙伴们很快的就过来占据了喵哈哈村的各个军事要地,牢牢的守住了喵哈哈村. 但是度度熊发现,这是一场旷日持久的战斗,所以度度熊决定要以逸…
#193. 「2019冬令营提高组」堆 但是每个点都遍历一遍,有些点的子树完全相同却重复算了 忽然记起完全二叉树的性质之一:每个非叶节点的子树中至少有一个是满二叉树 那么我们预处理满二叉树的那一块,剩下的dfs就可以辣 求阶乘.......分块打表 设打表分成$k$段,则复杂度$O(logn+n/k)$ #include<cstdio> ,W=1e7; ]={,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,…
题意 题目链接 Sol 分块打表,非常好的思想. 对于这种求$[A, B]$区间内xxx的数的个数,然后$B$又不算是特别大的题,考虑分段打表 每个块的大小为$10^5$,打$3 * 10^3$个.然后块内的暴力查,块外的暴力算 /* */ #include<cstdio> #include<cstdlib> #include<ctime> const int N = 3e8; , base = 1e5; void check(int x) { ; i * i <…
链接: https://vjudge.net/problem/Gym-100923H 题意: Oberyn Martell and Gregor Clegane are dueling in a trial by combat. The fight is extremely important, as the life of Tyrion Lannister is on the line. Oberyn and Gregor are measuring their skill in combat…