time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integ…
直接从1开始枚举不就行了... 思路如下: 1.先定义一个判断是不是质数的函数 int pd(int n) { if(n==1)return true; if(n==2)return false; for(int i=2;i*i<=n;i++) if(n%i==0)return true; return false; } 2.从1开始枚举,可以直接使用 for(int i=1;;i++) 进行枚举 3.判断i是否满足要求,调用函数,如果满足,就直接输出i并且break或return 0 for(…
我们可以发现,当n>2时,n·(n-2)+1=(n-1)·(n-1),因此,输出n-2即可. 如果n<=2,我们可以发现: 当n=2时,2·4+1=9不是质数,输出4即可: 当n=1时,1·3+1=4不是质数,输出3即可. 至此,此题就被我们解决了! AC代码: #include <bits/stdc++.h>//万能头文件 using namespace std;//使用标准名字空间 inline int read() { //快速读入 ,x=; char c=getchar()…
题面 CF755G PolandBall and Many Other Balls 给定 \(n\) 和 \(m\).有一排 \(n\) 个球,求对于每个 \(1\le k\le m\),选出 \(k\) 个球或相邻的球不能重复的方案数. 数据范围:\(1\le n\le 10^9\),\(1\le m<2^{15}\). 路标 这题是老经典题了,前人的描述也足够充分了. 但是蒟蒻尝试了这题的 \(3\) 种做法并记在笔记中后还是忍不住去挣咕值分享给大家. 这是的三种做法对比图(从下到上依次是倍…
http://codeforces.com/problemset/problem/755/A 题意:给出一个n,让你找一个m使得n*m+1不是素数. 思路:暴力枚举m判断即可. #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <string> #include <iostr…
题目链接:http://codeforces.com/contest/755 本蒟蒻做了半天只会做前两道题.. A. PolandBall and Hypothesis 题意:给出n,让你找出一个m,使n*m+1不是素数. 数据很小,直接暴力枚举. #include<cstdio> #include<iostream> #include<cmath> using namespace std ; bool prime( int n ) { for( int i = 2 ;…
题目:PolandBall and Hypothesis A. PolandBall and Hypothesis time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output PolandBall is a young, clever Ball. He is interested in prime numbers. He has stat…
1.PolandBall and Hypothesis 题面在这里! 大意就是让你找一个m使得n*m+1是一个合数. 首先对于1和2可以特判,是1输出3,是2输出4. 然后对于其他所有的n,我们都可以非常快的找到一个最小的与它互质的质数p(考虑反证法),并且满足p<n. 这样就相当与解一个同余方程 n*m = p-1 (mod p) , 解出的m可以保证 n*m+1 是 p 的倍数,也就是合数了. 又因为gcd(p,n)==1,所以这个方程肯定有解,直接求一个 n 在mod p意义下的逆元然后乘…
从神 Karry 的题单过来的,然后自己瞎 yy 了一个方法,看题解区里没有,便来写一个题解 一个常数和复杂度都很大的题解 令 \(dp_{i,j}\) 为 在 \(i\) 个球中选 \(j\) 组的方案数,则显然有转移 \(dp_{i,j}=dp_{i-1,j}+dp_{i-1,j-1}+dp_{i-2,j-1}\) 然后考虑对其优化: 令 \(f_i\) 为 \(dp_i\) 的生成函数,则 \(f_i\) 只与 \(f_{i-1}\) 和 \(f_{i-2}\) 有关,且关系为 \(f_i…
Content 给定无向图的 \(n\) 个点的父亲节点,求无向图的联通块个数. 数据范围:\(1\leqslant n\leqslant 10^4\). Solution 并查集模板题. 我们将在当前节点和它的父亲节点连在一起,然后看不同的祖先节点的个数即可. 没学过并查集的同学建议先去做 P3367 [模板]并查集. Code #include <cstdio> #include <algorithm> #include <cstring> #include <…
F. PolandBall and Gifts   It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutation p, pi ≠ i for all i. Unfortun…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already sa…
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard output PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve i…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 e…
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我没看,看不懂. 基本思路:我不会. 参考代码:找Oyk老师和Czj老师去. B. The background of water problem 题目大意(大写加粗的水题):给定$N$个学生和他们$K$个科目的成绩$S_i$,再给出各科目$K_i$的权重顺序$Q_i$,求排名之后,拥有id为$X$的…
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #include <string.h> #include <time.h> #include <stdlib.h> #include <string> #include <bitset> #include <vector> #include <…
2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2561 Description 给定一个边带正权的连通无向图G=(V,E),其中N=|V|,M=|E|,N个点从1到N依次编号,给定三个正整数u,v,和L (u≠v),假设现在加入一条边权为L的边(u,v),那么需要删掉最少多少条…
Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring Painting standard input/output 1 s, 256 MB    x2519 C Money Transfers standard input/output 1 s, 256 MB    x724 D Tree Construction standard input/outp…
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练. 题解: E666 这个题是让求有多少个子串只含有6.寻找连续的6,然后用n*(n+1)/2求出这一段的子串个数,然后把每一段连续的加起来. 做的时候wa了很多次,原来是在n*(n+1)的地方已经超过int型了,所以需要设置类型为long long. #include <cstdio> #inc…
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 57    Accepted Submission(s): 49 Problem Description Recently, paleoanthropologists have found historical remains on an…
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minecraft方块地图上(由很多1*1*1的方块搭起来的地图,最高5000),其中两块分别有高0.5米的激光塔,有一个高0.5米的机器人要从其中一个激光塔走到另一个.要求只能走相邻4个方向,每次不能爬上超过1格或跳下超过3格(咦,好像真的很像minecraft),要求每走到一个格子,机器人站在在这个格子的…
学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或者SPFA跑出来s-t最短路,然后把最短路DAG上的每条边的容量设为1,跑最小割即可. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #define INF ((~(…
求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & \equiv & a_2 \pmod{p} \\ & \vdots & \\ \sum_{i=1}^n x_i^n & \equiv & a_n \pmod{p}\end{array} \] 的解,或输出"NO". 题解 构造多项式\(\prod_i…
题意请看absi大爷的blog http://absi2011.is-programmer.com/posts/200920.html http://absi2011.is-programmer.com/posts/200822.html DAY1 T1 最优比率树形DP? 跟最优比率生成树很像..二分Σp/Σs(暂定为f 判定过程:每个点得到一个新权值f*p[i]-s[i] 做树形dp,dp[i][j]表示以i为根的子树选j个点能得到的最大权值 dp[root][k]>0则为合法 T2 T3…
又恬不知耻的开始写题解了,暑假到了,QAQ然而想我这样的弱逼是没有暑假的sad,还是老老实实刷题吧. 题目大意:给一个小车的宽度和长度和两条道路的宽度,判断小车能否通过. 思路:可以先看下面的图,我们可以得到高度h的表达式和角度 要使汽车能转过此弯道,那么就是汽车的左边尽量贴着那个直角点,而汽车的右下后方的点尽量贴着最下面的边. 我们以O点为原点建立直角坐标系,我们可以根据角a给出P点横坐标的函数F(a)   那么很容易得到:   其中有条件:,可以很容易证明是一个单峰函数,也可以不用证明,自己…
h3 { font-family: Consolas; color: #339966 } .math { font-family: Consolas; color: gray } 题目描述 Description Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光.Z小镇附近共有N(1<N≤500)个景点(编号为1,2,3,-,N),这些景点被M(0<M≤5000)条道路连接着,所有道路都是双向的,两个景点之间可能有多条道路.也许是为了保护该地的旅游资源,Z小镇有个奇怪的规定,就是对…
[前言] 感觉稍微有些滑稽吧,毕竟每次练的题都是提高组难度的,结果最后的主要任务是普及组抱一个一等奖回来.至于我的分数嘛..还是在你看完题解后写在[后记]里面.废话不多说,开始题解. 第一题可以说的内容不是很多吧.直接暴力,计算每种铅笔需要花费的金额. 只不过计算的时候,需要注意如下问题 如果不是整数倍,除完后要加1 神奇的Linux系统,很多人的第三个点wa了,所以要养成良好的编写代码的习惯 Code(我的源程序) #include<iostream> #include<fstream…
机器翻译 题解:模拟 #include <cstdio> #include <cstring> ; ], ]; int main(){ memset(, sizeof(in)); scanf(; ; i<m; i++){ scanf("%d", &cj); if (~in[cj]) continue; Pri ++; <=n) now ++, in[cj] = i; else { MinV = 0x3f3f3f3f; ; j<=MAXN…
四.应用题 ( 本大题共5 小题,50 分 ) 1. 假设某系统中有五个进程,每个进程的执行时间(单位:ms)和优先数如下表所示(优先数越小,其优先级越高). 进程 执行时间 优先数 P1 P2 P3 P4 P5 10 1 2 1 5 3 1 5 4 2 如果在0时刻,各进程按P1.P2.P3.P4.P5的顺序同时到达,请回答以下问题:(12分) (1)当系统采用先来先服务调度算法时: 进程执行顺序是      p1 p2 p3 p4 p5      平均周转时间是  13.4ms (2)当系统…
啊啊啊啊啊啊今天已经星期三了吗 那么,来一波题解吧 本题地址http://www.luogu.org/problem/show?pid=1006 传纸条 题目描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行n列的矩阵,而小渊和小轩被安排在矩阵对角线的两端,因此,他们就无法直接交谈了.幸运的是,他们可以通过传纸条来进行交流.纸条要经由许多同学传到对方手里,小渊坐在矩阵的左上角,坐标(1,1),小轩坐在矩阵的右下角,坐标(m,n).从小渊…