lightoj 1407 2-sat】的更多相关文章

这题的英语either...or....很蛋疼: m中,1:x与y至少一个出席:2:x出席,y随便,x不出席,y也不出席----这有个坑,可以推出y出席x也一定出席(这个关系必须要连上):3x与y至少一个不出席   4,x与y有且只有一个出席. 对于k中的数据:我琢磨很久,关系在图上是建不了的,type为1时三个人至少有一个人要出席,则三个都不出席的情况是不允许的,dfs的时候判断一下就是了,同理type为2的情况. #include<cstdio> #include<cstring&g…
M - M Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1261 Description SAT was the first known NP-complete problem. The problem remains NP-complete even if all expressions are written in conju…
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.com/ziyi--caolu/p/3236035.html http://blog.csdn.net/hcbbt/article/details/15478095 dp[i][j]为第i天到第j天要穿的最少衣服,考虑第i天,如果后面的[i+1, j]天的衣服不要管,那么dp[i][j] = dp[i…
检测凸多边形碰撞的一种简单的方法是SAT(Separating Axis Theorem),即分离轴定理. 原理:将多边形投影到一条向量上,看这两个多边形的投影是否重叠.如果不重叠,则认为这两个多边形是分离的,否则找下一条向量来继续投影.我们不需要比较很多条向量,因为已经在数学上证明,多边形每条边的垂直向量就是我们需要的向量. 1.AABB 让我们首先以AABB开始(AABB是一种两边分别平行于X-Y轴的矩形) 判断两个AABB是否碰撞,我们只需要投影两次,分别是投影在平行于X轴和Y轴的向量上…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1298 题意:给你两个数 n, p,表示一个数是由前 k 个素数组成的,共有 n 个素数,然后求这样的所有的数的欧拉和: 例如 n = 3, p=2; 前两个素数是2,3, 然后因为n=3,所以要再选一个素数组成一个数,有两种选择2*3*2=12 和 2*3*3=18 结果就是Φ(12)+Φ(18) = 10; 我们可以用dp[i][j] 表示前 j 个素数中选择 i 个的结果,Φ[n…
http://lightoj.com/volume_showproblem.php?problem=1214 这就是一道简单的大数取余. 还想还用到了同余定理: 所谓的同余,顾名思义,就是许多的数被一个数d去除,有相同的余数.d数学上的称谓为模.如a=6,b=1,d=5,则我们说a和b是模d同余的.因为他们都有相同的余数1. //// 数学上的记法为: a≡ b(mod d) 可以看出当n<d的时候,所有的n都对d同商,比如时钟上的小时数,都小于12,所以小时数都是模12的同商. 对于同余有三种…
相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's Fantabulous Birthday. 找规律题,左边列是1 3平方 5平方......下边行是1 2平方 4平方......,找到当前数被包夹的位置,然后处理一下位置关系,注意奇偶. 1010 Kinghts in Chessboard. 规律题,对于m,n大于2的情况下,使用交叉放置的方法…
Aladdin and the Flying Carpet Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1341 Appoint description:  System Crawler  (2016-07-08) Description It's said that Aladdin had to solve seven myst…
A - Bi-shoe and Phi-shoe Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1370 Appoint description:  System Crawler  (2016-07-08) Description Bamboo Pole-vault is a massively popular sport in X…
 Extended Traffic Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1074 Appoint description:  System Crawler  (2016-05-03) Description Dhaka city is getting crowded and noisy day by day. Certai…
Conquering Keokradong Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1048 Description This winter we are going on a trip to Bandorban. The main target is to climb up to the top of Keokradong.…
D - Harmonic Number Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1234 Description In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers: In th…
E - Help Hanzo Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1197 Description Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he ha…
B - Pairs Forming LCM Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1236 Description Find the result of the following code: long long pairsFormLCM( int n ) {    long long res = 0;    for( in…
1.LightOJ 1245   Harmonic Number (II)   数学题 2.总结:看了题解,很严谨,但又确实恶心的题 题意:求n/1+n/2+....+n/n,n<=2^31. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio> #define max(a…
1.LightOJ 1012  Guilty Prince  简单bfs 2.总结:水 题意:迷宫,求有多少位置可去 #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio> #define F(i,a,b) for (int i=a;i<=b;i++) using names…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1289 题意:求LCM(1, 2, 3, ... , n)%(1<<32), (1<n<=1e8); LCM(1, 2, 3, ... , n) = n以内所有素数的最高次幂之积,例如15: 23*32*5*7*11*13 = 36360360; 为了防止TLE所以,要有一个数组表示前缀积,但是直接开LL会MLE是,因为有个%1<<32刚好是unsigned…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1278 题意:给你一个数n(n<=10^14),然后问n能用几个连续的数表示; 例如: 15 = 7+8 = 4+5+6 = 1+2+3+4+5,所以15对应的答案是3,有三种; 我们现在相当于已知等差数列的和sum = n, 另首项为a1,共有m项,那么am = a1+m-1: sum = m*(a1+a1+m-1)/2  -----> a1 = sum/m - (m-1)/2 a…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意:给你一个数n,求有多少对(i,  j)满足 LCM(i, j) = n, (i<=j),  n <= 1e14: 之前做的那道LightOj 1215 中有说过:LCM(x, y) = ∏(所有质因子幂高的项之积); 那么本题就先把n分解质因子幂的形式,即 n = p1a1*p2a2*...*pkak;(pi为质数) 现在先不管i和j的大小,当 i 中包含因子p1a1时…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1220 题意:已知 x=bp 中的 x 求最大的 p,其中 x b p 都为整数 x = (p1a1*p2a2*p3a3*...*pkak), pi为素数;则结果就是gcd(a1, a2, a3,...,ak); 当x为负数时,要把ans缩小为奇数; #include <stdio.h> #include <string.h> #include <iostream&…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1215 题意:已知三个数a b c 的最小公倍数是 L ,现在告诉你 a b  L 求最小的 c ; 其实就是告诉你(最小公倍数LCM)LCM(x, y) = L 已知 x 和 L 求 最小的 y ; L = LCM(x, y)=x*y/gcd(x, y);如果把x,y,L写成素因子之积的方式会很容易发现 L 就是 x 和 y 中素因子指数较大的那些数之积; 例如LCM(24, y)…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1213 #include <stdio.h> int cases, caseno; int n, K, MOD; int A[1001]; int main() { scanf("%d", &cases); while( cases-- ) { scanf("%d %d %d", &n, &K, &MOD); i…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1197 题意:给你两个数 a b,求区间 [a, b]内素数的个数, a and b (1 ≤ a ≤ b < 231, b - a ≤ 100000). 由于a和b较大,我们可以筛选所有[2, √b)内的素数,然后同时去筛选掉在区间[a, b)的数,用IsPrime[i-a] = 1表示i是素数: ///LightOj1197求区间素数的个数; #include<stdio.h&g…
拓展欧几里得入门题 两个野人若要走到同一个洞穴,设他们走了x步,则p[i]*x+c[i]≡p[j]*x+c[j](mod ans),ans即答案: 移项得到(p[i]-p[j])*X+ansY=c[j]-c[i]; 即aX+bY+=C的形式,枚举ans,n^2的枚举每一个野人,用ex_gcd求得最小解,看X是否在他们的生命时间内. /************************************************************** Problem: 1407 User:…
http://www.lightoj.com/volume_showproblem.php?problem=1013   Yes, you are developing a 'Love calculator'. The software would be quite complex such that nobody could crack the exact behavior of the software. So, given two names your software will gene…
http://www.lightoj.com/volume_showproblem.php?problem=1011 You work in a company which organizes marriages. Marriages are not that easy to be made, so, the job is quite hard for you. The job gets more difficult when people come here and give their bi…
Harmonic Number Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1234 Description In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers: In this p…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1163 题意:有一个数A,然后去掉A的最后一位得到B,先告诉你A-B的值,求所有满足条件的A,按从小到大的顺序输出; 其实就是x-x/10=n求所有的 x(这里的x/10是取整) 还可以写成是:num*10+r - num = n,其中num*10+r = A, r = B:r一定是0-9中的一个数,可以枚举,所以可以得到 9 * num = n-r; 所以只要找到所有的r是的(n-r…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出impossible 可以用二分求结果,重点是求一个数的阶乘中末尾含有0的个数,一定和因子5和2的个数有关,因子为2的明显比5多,所以我们只需要求一个数的阶乘的因子中一共有多少个5即可; LL Find(LL x) { LL ans = ; while(x) { ans += x/; x /= ;…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1098 题意:给你一个数n (0 ≤ n ≤ 2 * 109),求n以内所有数的因子和,保证结果在LL范围内 我们可以枚举2-sqrt(n)的每个数出现的次数,然后再找到对应因子大于sqrt(n)的数出现数的和; 例如2的倍数4 6 8 10,对应的因子就是2 3 4 5; 时间复杂度为sqrt(n)*T; #include <stdio.h> #include <string…