经典例题
XerxesSimon
折柳为笔..月光为笺..画下你月华般的容颜.. 烟染三月..提诗两行..刻下我如梦般的臆想..
展开
-
断案
http://codeforces.com/problemset/problem/156/B题目大意:福尔摩斯正在处理一件案子。此时已经抓捕了n个嫌疑人,里面只可能有一个是真正的犯人。福尔摩斯正在审问这些嫌疑人。每个嫌疑人的回答只有两种,一种表明他说编号为i的嫌疑人不是犯人,用-i表示;另一种表明他说编号为i的嫌疑人是犯人,用+i表示。聪明的福尔摩斯已经知道了其中有m个人说的是转载 2016-05-10 19:29:55 · 500 阅读 · 0 评论 -
表达式求值
http://acm.nyist.net/JudgeOnline/problem.php?pid=35 #includeusing namespace std;const int N=1e3+7;const int inf=0x3f3f3f3f;char str[N];stack num;stack op;int priority(char c){ if(c=='+'原创 2016-07-24 18:28:38 · 312 阅读 · 0 评论 -
Examining the Rooms
出处http://blog.csdn.net/acm_cxlove/article/details/7854526 by---cxlove题目:给出N个房间,每个房间的钥匙随机放在某个房间内,概率相同。有K次炸门的机会,求能进入所有房间的可能性为多大。http://acm.hdu.edu.cn/showproblem.php?pid=3625钥匙与门的对应关系呈现出转载 2016-07-08 17:51:45 · 339 阅读 · 0 评论 -
Exponentiation --Java
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=3&problemid=2import java.math.*;import java.util.Scanner;public class Main{ public static void main(String[] args)原创 2016-07-07 17:16:23 · 299 阅读 · 0 评论 -
汉诺塔VII
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=2&problemid=3每次最大的盘 只能放在a->c#includeusing namespace std;int f[30];int dfs(int n,int a,int c,int b){ if(n<=0) retu原创 2016-07-04 17:55:22 · 347 阅读 · 0 评论 -
小数化分数
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1717整数化小数,不循环的小数容易化。对于循环小数化分数原理如下:⑴ 把0.4747……和0.33……化成分数。例1: 0.4747……×100=47.4747…… 0.4747……×100-0.4747……=47.4747……-0.4747原创 2016-05-22 18:17:33 · 415 阅读 · 0 评论 -
Fibonacci
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=2&problemid=1用到了斐波那契数列的通项公式。先看对数的性质,loga(b^c)=c*loga(b),loga(b*c)=loga(b)+loga(c);假设给出一个数10234432,那么log10(10234432)=原创 2016-05-22 17:53:41 · 327 阅读 · 0 评论 -
N^N的第一位数
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=1&problemid=11对一个数num可写为 num=10n + a, 即科学计数法,使a的整数部分即为num的最高位数字numnum=10n + a 这里的n与上面的n不等两边取对数: num*lg(num) = n + lg(a);原创 2016-05-22 17:49:44 · 665 阅读 · 0 评论 -
HDU Crixalis's Equipment (贪心)
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1§ionid=3&problemid=19#includeusing namespace std;const int N=1e3+7;struct node{ int a,b;};node g[N];bool cmp(node x,node y原创 2016-05-21 11:07:02 · 299 阅读 · 0 评论 -
2016暑假的好题
POJ 2353#include #include #include #include #include #include #include #include #include #include #include #define MAX 110using namespace std;double x[MAX],y[MAX],dp[MAX][MAX];double d原创 2016-08-08 17:33:41 · 316 阅读 · 0 评论 -
Max Sum
Max Sumhttp://acm.hdu.edu.cn/showproblem.php?pid=1003#includeusing namespace std;const int N=1e5+7;const int inf=0x8fffffff;int main(){ int i,j,k,m,n,t,tt=0; cin>>t; while(t--)原创 2016-08-13 11:04:02 · 238 阅读 · 0 评论 -
最佳淘汰算法
4272: 最佳淘汰算法Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 412 Solved: 64DescriptionLyf在做操作系统作业的时候,遇到了一题要他实现下Opt算法(全称页面置换最佳淘汰算法)。可是Lyf发现最近好忙啊,于是他想请他的学弟,学妹们帮他来完成。作业里的内容是这样的:提出最佳页面淘汰算法原创 2017-03-29 08:57:33 · 5555 阅读 · 0 评论 -
在N个乱序数字中查找第k大的数字
若随机选取枢纽,线性期望时间O(N)#includeusing namespace std;const int N=1005;int a[N];int qs(int l,int r){ int x=a[l]; while(l<r) { while(l=x) r--; a[l]=a[r]; while(l<r&&a转载 2017-03-10 22:26:45 · 805 阅读 · 0 评论 -
LCA最近公共祖先(RMQ、Tarjan)
今天学LCA,先照一个模板学习代码,给一个离线算法,主要方法是并查集加上递归思想。http://poj.org/problem?id=1330再搞,第一个离线算法是比较常用了,基本离线都用这种方法了,复杂度O(n+q)。通过递归思想和并查集来寻找最近公共祖先,自己模拟下过程就可以理解了。 然后就是在线算法,在线算法方法就很多了,比较常用的是LCA的RMQ转换,然原创 2016-07-11 12:51:27 · 401 阅读 · 0 评论 -
快速幂(普通快速幂、矩阵快速幂)
题目地址:HDU 2604 Queuing题意: n个人排队,f表示女,m表示男,包含子串‘fmf’和‘fff’的序列为O队列,否则为E队列,有多少个序列为E队列。分析: 矩阵快速幂入门题。 下面引用巨巨解释:用f(n)表示n个人满足条件的结果,那么如果最后一个人是m的话,那么前n-1个满足条件即可,就是f(n-1); 如果最后一个是f那么这个还无法推出原创 2016-07-10 11:28:16 · 422 阅读 · 0 评论 -
树( Be Friends)
https://www.bnuoj.com/v3/contest_show.phpcid=8506#problem/B#includeusing namespace std;typedef long long ll;const int N=100010,M=N*32;int n,a[N],q[N],son[M][2],tot;ll ans;void ins(int p){ fo原创 2016-11-06 14:33:57 · 338 阅读 · 0 评论 -
二分&三分
http://acm.hdu.edu.cn/game/entry/problem/list.php?chapterid=4§ionid=1经典的三分HDU 3400 Line belt (三分再三分)ACM题目地址: HDU 3400 Line belt题意: 就是给你两条线段AB , CD ,一个人在AB以速度p跑,在CD上以q原创 2016-07-10 16:09:34 · 396 阅读 · 0 评论 -
测试
int lis(){ int len=0; for(int i=0;i<n;i++) { int k=lower_bound(f,f+len,a[i])-f;//upper_bound(); f[k]=a[i]; if(k==len) len++; } return len;}原创 2016-08-15 09:51:07 · 261 阅读 · 0 评论 -
OpenJudge_P3531 判断整除(DP)
总时间限制: 1000ms 内存限制: 65536kB 描述 一个给定的正整数序列,在每个数之前都插入+号或-号后计算它们的和。比如序列:1、2、4共有8种可能的序列: (+1) + (+2) + (+4) = 7 (+1) + (+2) + (-4) = -1 (+1) + (-2) + (+4) = 3 (+1) + (-2) + (-4) = -5 (-1) +转载 2016-08-26 09:28:54 · 1457 阅读 · 0 评论 -
ACM-大数N!的位数公式
!求解位数下面介绍两种方法直接求阶乘结果的位数:方法一 可以将n!表示成10的次幂,即n!=10^M(10的M次方)则不小于M的最小整数就是 n!的位数,对该式两边取对数,有 M =log10^n!即: M = log10^1+log10^2+log10^3...+log10^n 循环求和,就能算得M值,该M是n!的精确位数代码:转载 2016-06-07 21:06:28 · 807 阅读 · 0 评论 -
第四届河南省程序设计大赛
http://acm.nyist.net/JudgeOnline/problem.php?pid=305#includeusing namespace std;const int N=1e3+7;const int mod=1e9+7;const int inf=0x3f3f3f3f;typedef long long ll;char str[1005];int start;i原创 2016-05-29 11:11:08 · 576 阅读 · 0 评论 -
第五届河南省程序设计大赛
http://acm.nyist.net/JudgeOnline/problem.php?pid=540http://acm.nyist.net/JudgeOnline/problem.php?pid=541 //package jav;import java.io.*;import java.math.BigDecimal;import java.util.*;public原创 2016-05-29 11:16:18 · 366 阅读 · 0 评论 -
第三届河南省程序设计大赛
http://acm.nyist.net/JudgeOnline/problem.php?pid=168 #includeusing namespace std;int dp[200];int main(){ int n,t,i,j,ans; scanf("%d",&t); while(t--) { int a,b,c;原创 2016-05-28 18:01:20 · 523 阅读 · 0 评论 -
dfs
https://www.bnuoj.com/v3/problem_show.php?pid=4049#include#include#include#include#include#include#includeusing namespace std ;const int N=6;//10+1e2;int f[20][20];string ans[N];int same(原创 2016-04-21 13:44:30 · 269 阅读 · 0 评论 -
积木积水
http://gdutcode.sinaapp.com/problem.php?cid=1031&pid=4找到最长的那个柱子,在水满的情况下,从前往后,在它左边水面是非递减的,右边是非递增的(如果从最后一个柱子往中看也是非递减的)#include #include #include #include #include #include #include #inclu原创 2016-04-13 22:11:34 · 540 阅读 · 0 评论 -
"多米诺骨牌"问题的动态规划算法
现有n块”多米诺骨牌”s1,s2,s3,...sn水平放成一排,每次骨牌si包含左右两个部分,每个部分赋予一个非负整数值,如下图所示为包含6块骨牌的序列.骨牌可做180度旋转,使得原来在左边的值变到右边,而原来右边的值移到左边,假设不论si如何旋转,L[i]总是存储si左边的值, R[i]总是存储si右边的值, W[i]用于存储si的状态:当L[i] 求:R[1]*L[2]+R[2]*L[原创 2016-04-12 19:48:48 · 4808 阅读 · 1 评论 -
圆盘
http://dmnotdm.cn/problem.php?id=1015#include#include#include#include#include#include#includeusing namespace std;int n,m,mid;long long ans,tmp,a[200001],dis; void input(){ cin>>n>>原创 2016-05-04 15:19:00 · 572 阅读 · 0 评论 -
JAVA大数
http://acm.fzu.edu.cn/problem.php?pid=2036fzu 2036 Log Calculator原创 2016-05-12 16:17:25 · 233 阅读 · 0 评论 -
判断多边行对称
题目地址:http://acm.fzu.edu.cn/problem.php?pid=2035其实这题也是一样的:http://acm.hdu.edu.cn/showproblem.php?pid=3902题目意思也很好懂,就是处理如何判断多边行是否对称。先找出所有点的中点,然后一共有2×N个点,依次检查是否关于XY的连线对称如果存在对称轴,必定是点i和点i+n连成原创 2016-05-10 20:01:29 · 1008 阅读 · 0 评论 -
第八届河南省程序设计大赛
http://acm.nyist.net/JudgeOnline/problem.php?pid=1236 #include//c++#include//数学公式#include//malloc#include#include#include//输入输出#include//快排#include//队列#include//优先队列#include//栈#include/原创 2016-05-29 15:11:28 · 532 阅读 · 0 评论 -
第六届河南省程序设计大赛
http://acm.nyist.net/JudgeOnline/problem.php?pid=709http://acm.nyist.net/JudgeOnline/problem.php?pid=710 #include #include #include using std::sort;struct Node{ double left, right;} arr原创 2016-05-29 11:23:58 · 402 阅读 · 0 评论 -
三个圆的相交面积
http://acm.hzau.edu.cn/problem.php?id=1003#include #include #include #include using namespace std;void solve(){ double d, r; cin >> d >> r; double ans = 0; if (d < r) { double a =原创 2016-05-20 12:16:09 · 4524 阅读 · 0 评论 -
概率论
http://acm.hzau.edu.cn/problem.php?id=1013#include #include #include #include #include #include #include #include #include #include #include #include using namespace std;const int MAXN原创 2016-05-20 12:12:11 · 632 阅读 · 0 评论 -
n^n%10
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1§ionid=2&problemid=12#include #include #include #include #include using namespace std ;int arr [ 20 ] = { 1 , 4 , 7 , 6 , 5 , 6原创 2016-05-20 11:54:37 · 539 阅读 · 0 评论 -
HZAUoj 1016: Array C 【贪心】
题目链接:HZAUoj 1016: Array C 【贪心】#include #include #include #include #include #include #include #include #include #include #define CLR(a, b) memset(a, b, sizeof(a))using namespace std;typ原创 2016-05-19 18:09:31 · 339 阅读 · 0 评论 -
HZAUoj 1015: LCS
题目链接:HZAUoj 1015: LCS #include #include #include #include #include #include #include #include #include #include #define CLR(a, b) memset(a, b, sizeof(a))using namespace std;typedef lon原创 2016-05-19 18:08:04 · 427 阅读 · 0 评论 -
HZAU 1001 Handing Out Candies
http://acm.hzau.edu.cn/problem.php?id=1001#include #include #include #include #include #include using namespace std;void solve(){ long long n, k; cin >> n >> k; long i = k / n; long原创 2016-05-19 18:05:53 · 376 阅读 · 0 评论 -
等差数列
http://acm.hzau.edu.cn/problem.php?id=1019题意很简单,给我们一个序列,问我们从这个序列中选出一些数能构成的最长的等差序列的长度为多少。这个问题我们用DP来解决,首先因为我们取数是不用关注它的顺序的,所以我们就可以先排个序,然后我们用dp[i][j]表示取到第i个数的时候间距为j的长度的等差数列最长的长度,所以我们有状态转移方程dp[i]原创 2016-05-19 18:03:07 · 526 阅读 · 0 评论 -
考试排名
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1§ionid=3&problemid=12#includeusing namespace std;struct node{ int a,b; char c[20];};node g[1000];bool cmp(node x,node y){原创 2016-05-18 13:53:16 · 533 阅读 · 0 评论 -
求解一个矩阵的逆矩阵
c++#includeusing namespace std;const int N=20;const double E=1e-10;double calculate_A(double src[N][N], int n ){ int i,j,k,x,y; double tmp[N][N], t; double result = 0.0; if(n ==原创 2017-04-12 14:46:32 · 3208 阅读 · 0 评论