自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

[Q]4EchoNStef

没人能逼着你刷题,更没人能阻止你刷题

  • 博客(250)
  • 资源 (1)
  • 收藏
  • 关注

转载 ural 1846. GCD 2010(线段树)

题意:求n个点的最大公约数,有两种操作,增加一个数,删去一个数,删去的数肯定是已经存在的离线处理,先要离散化然后找到每个数相应的位置插入或删除,简单的单点更新gcd(a,b,c,d)=gcd(gcd(a,b),gcd(c,d));#include#include#include#includeusing namespace std;#def

2013-08-07 15:20:24 1292 1

原创 ural 1586. Threeprime Numbers

题意:定义这样一种数:Threeprime,指对于它的任意连续3位上的数字,都构成一个3位的质数。求对于一个n位数,存在多少个Threeprime数。读入一行,一个整数n(3输出一行,即总数mod 10^9+9。解法:记录[100, 1000)范围内的所有的素数(是素数的每一位)。然后从n = 4往后,定义dp[i][x2][x3], i表示到第i位时,第i-1位为x2

2013-08-06 14:00:07 998

转载 ural 1207. Median on the Plane(极角排序)

题意是求一堆点中的两个点,其连接的直线线要能等分所有点。#include #include #include #include #include #include #include #include #include using namespace std;const int MAX = 10010;const double eps = 1e-6;struct poin

2013-08-06 10:09:00 1164

转载 ural 1019 Line Painting (线段树)

#include #include #include using namespace std;#define MAX 1000000000#define N 10010#define M 5010#define lch(i) ((i)<<1)#define rch(i) ((i)<<1|1)#define min(a,b) a<b?a:b#define max(a,b) a>b

2013-08-05 16:33:30 961

原创 ural 1090. In the Army Now

树状数组的wiki页面:http://zh.wikipedia.org/wiki/%E6%A0%91%E7%8A%B6%E6%95%B0%E7%BB%84题意:给出士兵的身高站位求逆序数,本题中是求某人前面比他矮的人的个数和。#include #include #include using namespace std;const int N = 10007;int c[N]

2013-08-05 12:01:21 1086

原创 ural 1078 Segments

给出x轴上的线段的端点坐标,一个线段能覆盖另一个线段(端点不能相同),求出最多的线段覆盖并且从短到长给出路径。#include #include using namespace std;int N,A[500],B[500],memo[500],choice[500];int solve(int last){ int &ret = memo[last];

2013-08-05 11:13:51 1022

转载 URAL 1038 Spell Checker

这个题目可以用有限自动机的理论去做,也可以在设定好各个状态后枚举可能的情况并跳转状态,比如句子已经结束这个状态设为0,处于单词中这个状态设为1,在句子中间非单词部分时这个状态设为2,这样如果处于状态0但是遇到了小写字母就算是一个错误,处于状态1但遇到了大写字母也算是一个错误。#include#include#include#define MAXD 100010int N, cnt;c

2013-08-05 10:14:26 886

转载 1039. Anniversary Party (dp)

树DP经典问题,公司聚会,下属和直属上司不能共存,给出每个人的快乐值,再给出每个人的编号和他的上司,选出一些人参加聚会使快乐值最大/*从叶子开始选择,每个节点只有选不和不选两种可能,dp[rt][0],dp[rt][1]分别表示选和不选该节点dp[rt][1]=sum{ dp[son][0] }+val[rt] , 因为跟选了它的儿子就全部不能选dp[rt][0

2013-08-05 09:49:57 732

转载 ural 1029. Ministry (dp)

Mr. F. wants to get a document be signed by a minister. A minister signs a document only if it is approved by his ministry. The ministry is an M-floor building with floors numbered from 1 to M, 1A

2013-08-05 09:38:09 945

转载 ural 1306(堆-优先级序列)

很大数量的数,求中位数思路:此题不能存储所有元素,否则会MLE,想到用优先队列(默认值大的优先级高),存储一半,剩下的一半依次和队首比较,若小于队首,则将队首元素出队,新元素入队。最后,若n为奇数,队首元素即为中间值;n为偶数,队列前两个的平均值为答案。#include #include #include #include #include using name

2013-08-02 10:12:38 1081 1

转载 1874. Football Goal

二分法作为分治中最常见的方法,适用于单调函数,逼近求解某点的值。但当函数是凸性函数时,二分法就无法适用,这时三分法就可以“大显身手”~~       如图,类似二分的定义Left和Right,mid = (Left + Right) / 2,midmid = (mid + Right) / 2; 如果mid靠近极值点,则Right = midmid;否则(即midm

2013-07-31 16:16:58 893

原创 ural 1656. Far Away Kingdom's Army(bfs)

题意:有一个方阵有n行n列(3求一种可行的方案将他们排在方阵中,使得同一行、同一列中,高度总是从中间向两边递减解法:对输入的数据从大往小遍历,对矩阵从中央开始进行bfs即可。貌似是桶排序。#include #include using namespace std;const int mov[4][2]={0,1,0,-1,1,0,-1,0};int n,tot,arr[201

2013-07-31 14:35:34 849

原创 ural 1685. Orthography (树的遍历)

#include #include #include using namespace std; char s[20001],ans[20001]; void workk(int l,int r,int ll,int rr){ if (l>r) return; if (l==r){ans[ll-1]=s[l-1];return;} int mid=(ll+rr

2013-07-31 10:38:51 1515

原创 ural 1080. Map Coloring(二分染色bfs)

#include #include #include #include using namespace std;int map[105][105];int pay[105];int n;queueQ;void init(){ memset(pay,-1,sizeof(pay)); memset(map,0,sizeof(map)); whi

2013-07-31 10:21:33 1399

转载 ural 1087. The Time to Take Stones(博弈)

/*思路是这样的,f[t]=1表示还剩t个子时先手是能赢的,f[t]=0表示先手会输,递推公式是这样的 f[t] = 1 当且仅当存在某个i,使f[t-k[i]]=0,因为先手可以直接拿k[i]个。*/#include using namespace std;int main(){ int n,m,i,j; cin>>n>>m; int* k = new int[m]; int*

2013-07-31 10:07:02 931

原创 1081. Binary Lexicographic Sequence(dp)

题意:给出一个串的长度n,串只有0,1组成,但是不能有两个相邻的1。按字典序给串排列,最先肯定是0000,接着是0001,依此类推。给一个数字m,输出在长度为n的情况下,第m个排列的串是什么,如果m大于总排列数,输出-1思路:递推。首先,计算满足条件的N位序列的总个数。设为f[n]f[n]=f[n-1]+f[n-2]可是这样理解:长度为N的序列对应于:1.长度为N-

2013-07-31 09:32:54 870

转载 ural 1028. Stars (线段树)

jasison君我来无耻地抄(xue)写(xi)代码了~#include #include struct Node{ int a, b, cover; Node() {} Node(int _a, int _b): a(_a), b(_b), cover(0) {} int middle() { return (a+b)>>1; }} t[66000];void build

2013-07-30 17:26:38 918

原创 ural 1073. Square Country

完全背包问题。#include using namespace std;#define Min(a,b) (a)<(b)?(a):(b)#define MAXN 60010int main(){ int n; int i,j,dp[MAXN]; while(cin>>n) { for(i = 0; i <= n; i++) { dp[i] = i; }

2013-07-30 16:06:50 734

原创 Ural 1260. A nudnik photographer(dp)

题目:对1到N这些数进行排列,1在最左边,相邻的两个数之差不能超过2,求有多少种排列方法?解法:dp[i] = dp[i-1] + dp[i-3] + 1;解释:对dp[n],有3种情况:1、12……(dp[n-1])2、1324……(dp[n-3])3、1357……8642(一种确定的情况)代码:#include using namespace std;int

2013-07-30 11:00:11 871

原创 ural 1864. Get-Together at Den's (坑爹浮点数)

水题一道,要注意两点:1、题目中分配方式没有说明清楚2、浮点数下取整的时候要注意,比如4.9999999其实应该是5#include #include using namespace std;int main(){ long double n,arr[107],sum=0,cnt=0,mark[107]={0},sum2=0; cin>>n;

2013-07-29 15:03:11 1058

原创 ural 1024. Permutations (置换群)

算法:对于第i个数,模拟计算出其置换周期,记为ai,答案就是所有ai的最小公倍数。     1 2 3 4 5     4 1 5 2 3次数:3 3 2 3 2,最小公倍数6.#include #include int gcd(int a, int b){ if (b == 0) return a; else

2013-07-29 14:03:48 933

转载 Ural 1018 Binary Apple Tree(树形dp)

题意:一棵二叉苹果树,每个树枝上都有苹果,求剪枝后剩下Q根树枝的时候的最大苹果数量。(剪枝的时候不能连根拔起)思路:TreeDP。先由题给出的关系建立一棵二叉树,把边上的苹果移动到子结点,然后对树进行自底而上的DP,状态转移方程式为:f[root][j]=max(f[root.lc][i]+f[root.rc][j-1-i])+val[root],maxx);意思就是说当根root要保留j个点

2013-07-29 13:39:16 966

转载 ural 1017. Staircases(dp)

1017. StaircasesTime limit: 1.0 secondMemory limit: 64 MBOne curious child has a set of N little bricks (5 ≤ N ≤ 500). From these bricks he builds different staircases. Staircase consists

2013-07-29 11:48:24 850

转载 Ural 1016. Cube on the Walk (bfs滚骰子)

题意:个立方体放在国际象棋棋盘的一个格子上,该立方体每一面都和棋盘的格子一样大。该立方体每一面都标有一个非负整数。你可以在棋盘上滚动该立方体,在这期间计算立方体底面数字的和。你的任务是找出一条从给定的起点到终点的路径,使得前面所说的和最小。比较麻烦的题。#include #include #include #include #include #include using na

2013-07-29 11:23:17 770

原创 Ural 1320. Graph Decomposition(并查集,连通分支边数)

题意:一个图,每次删掉相邻的两条边,问能否把全部的边删完。解法:若图的每个连通分量都有偶数个边就输出1,否则输出0;#include #include #include using namespace std;int parent[10000],depth[10000];void Make_Set(int x){ parent[x] = x; depth[x

2013-07-26 16:04:05 891

原创 拓扑排序

参见ural 1022#include#include#define MAXD 110#define MAXM 10010int N, cnt, e, first[MAXD], next[MAXM], v[MAXM], topo[MAXD], vis[MAXD];void add(int x, int y){ v[e] = y; next[e] = first[x]

2013-07-25 15:10:08 678

原创 ural 1022. Genealogical Tree 拓扑排序

#include#include#define MAXD 110#define MAXM 10010int N, cnt, e, first[MAXD], next[MAXM], v[MAXM], topo[MAXD], vis[MAXD];void add(int x, int y){ v[e] = y; next[e] = first[x], first[x] =

2013-07-25 15:09:07 706

原创 Ural 1126. Magnetic Storms

给定一个数组,求M连续的和的最大值。用到的数据结构是单调队列。#include #include using namespace std;struct Node { int value, index;}; //存储每个元素的数值和下标int main(){ int m; s

2013-07-24 17:03:37 736

原创 ural 1725. Sold Out!

题意:某人坐在影院某排的某个位置,其他位置空。其它人可以选择从左侧或右侧入座,经过此人时,跨过他的脚然后入座。问要使所有人入座,比人跨过自己脚的最大次数。当从两边入座经过的人相等时,选择距离最短的一侧走。水题。#include using namespace std;int main(){ int n,k; cin>>n>>k; if(n

2013-07-23 16:42:25 809

原创 ural 1203. Scientific Conference(dp)给定N个区间,求最大的不相交的区间数

给定N个区间,求最大的不相交的区间数//动态规划,递推公式:f[i] = max(f[i-1],f[g[i]-1]+1);//f[i]表示时间0~i最多所能听的报告数,g[i]表示所有以时间 i 结束的报告中,最晚的开始时间。#include #include #include #include #include #include using namespace std;c

2013-07-23 14:20:42 1786

原创 最大连续子序列和

long long maxsequence3(long long a[], int len){ long long maxsum, maxhere; maxsum = maxhere = a[0]; //初始化最大和为a【0】 for (int i=1; i<len; i++) { if (maxhere <= 0) maxhe

2013-07-23 13:43:59 701

原创 ural 1136. Parliament (通过后序遍历构建二叉搜索树)

对于一个后序遍历序列,它可以分解为   (左子树部分)(右子树部分)(根),由于是查找树,可知(左子树)(根)所以对于当前一个区间内的序列[l,r],可以知道r下标对应的数值一定是当前子树的根,然后找到一个下标k,  [l,k-1] 里面的数值都小于根,他们是左子树 , [k,r-1]里面的数值都大于根,他们是右子树,这样就可以递归建树下去了。建树之后直接用新的规则后序遍历二叉树即可

2013-07-22 12:05:47 808

原创 Ural 1146. Maximum Sum

DP,最大子矩阵和:先按列压缩为一维i,如将每一列从左至右递加至一个一位数组,再用最大连续子序列和来求。/*最大子矩阵和,先压缩为一维再求最大子序列和,时间复杂度O(n^3)*/#include #include #define N 1100#define INF 0x3f3f3f3fint a[N][N],s[N],n;void get_sum(int x ,int y)

2013-07-19 16:49:23 803

原创 ural 1180. Stone Game (博弈)

#include using namespace std;int main(){ int i, j, h; char n[300]; cin>>n; h = strlen(n); j = 0; for (i=0; i<h; i++) j = (j * 10 + (n[i] - '0')) % 3; if (j == 0) cout<<2<<endl; else

2013-07-17 16:26:16 676

原创 poj1733 & Ural 1003 Parity Game (hash+并查集 )

长度为n的0和1组成的字符串, 然后问第L和R位置之间有奇数个1还是偶数个1.根据这些回答, 判断第几个是错误(和之前有矛盾)的。一旦发现有矛盾了,要马上跳出循环, 后面的那些数据不用去管他了,否则如果用continue就WA。#include #include #include using namespace std;const int MAXX=10005;in

2013-07-16 15:25:17 949

转载 sicily 1527. Tiling a Grid With Dominoes

有一个4xn的棋盘,无限个1x2的多米诺骨牌。输入n,求把棋盘完美覆盖的方法数。方法如下二维数组dp[n][m]表示有n列且该列状态为m的时候的排列方法数。m用四位二进制表示,第a位表示该列第a行的状态,1已经覆盖,0表示没有被覆盖。初始状态为:dp[1][3]=dp[1][6]=dp[1][12]=dp[1][15]=dp[1][0]=1;状态转移:    dp[t][1

2013-06-04 11:32:34 1817

转载 sicily 1345. 能量项链(dp)

http://soj.me/1345类似矩阵连乘。/*dp,n颗珠子,求最后剩下一颗珠子能放出最大能量d[i][j]表示第i颗珠子开始,长度为j的珠子所释放的最大能量转移方程:d[i][j] = max(d[i][j] ,d[i][k]+d[x][j-k] + node[i].head * node[x].head * node[y].rear) ; 其中1<=i<=n

2013-06-04 11:05:20 1669

原创 poj 1013 great equipment(背包,dp)

A - Great EquipmentTime Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %lluSubmit StatusDescriptionOnce upon a time, there lived Catherine Ironfist, the Queen of Enro

2013-05-15 01:20:42 1281

原创 Sicily 1796. Max's kingdom

注意用到的结构 map > ,sort就行了。#include #include #include #include using namespace std;int main(){ int n,p,a,sum,mid,i; map >::iterator mit; while (cin>>n) { map > m;

2013-02-04 14:00:11 504

原创 Sicily 1784. Road Toll (Dijkstra变形)

#include #include #include #include using namespace std;double adj[250][250],dis[250]; //dis[]记录从起点到该点扣完费后剩下的最大钱数int n,a,b;bool vis[1000];void dijkstra(){ int u; for(int i=1;i<=n;++i)

2013-02-04 12:10:14 665

Socket(C++,基于TCP)在线实时聊天程序

Socket(C++,基于TCP)在线实时聊天程序

2013-03-11

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除