自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

梦想天生

Algorithm & SGU & Codeforces & Math & CS Knowledge

  • 博客(24)
  • 收藏
  • 关注

原创 DP:斜率优化 Slope optimization

以HDU3507为例,讨论一下斜率优化问题。    http://acm.hdu.edu.cn/showproblem.php?pid=3507    题意:N个数字分段输出,输出每段(第i个到第j个)的代价是i到j的平方加上常数m,问输出所有N个数字的最小代价。    设dp[i]表示从第1个到第i个数字的代价,显然有dp[i] = min(dp[j] + (sum[i]-sum[j

2014-02-16 15:13:56 1249

原创 C++:函数与递归 Function and Recursion

1. 函数调用堆栈、作用域、形参与实参所谓“堆栈”,实际上就是个栈,和“堆”没有任何关系,只是都这么说而已。它的执行原理是:当函数A被调用时,它作为堆栈顶部的函数调用。A调用函数B时,B的函数调用加入栈成为新的顶部。B调用完时,退栈,控制权又回到了A。最底层的调用是main函数。如果变量在一个函数调用中被创建,则这个函数调用就是它的作用域—— 一旦函数调用被退栈,它也会被随之销毁。最后

2014-02-03 17:50:13 2039

原创 SGU118 数学题 Math

问题:令f(n)为n各个位数字之和。n的Digital Root是f(f(...f(n))),是一位数字。现在给你A1,A2...An,n个数,求A1*A2*…*AN + A1*A2*…*AN-1 + … + A1*A2 + A1的Digitial Root。Problem: Let f(n) be a sum of digits for positive integer n. If f(n)

2014-01-30 17:19:19 1233

原创 SGU117 水题 Easy

问题:N个数中有多少个数的M次方能被K整除。Problem: Find amount of numbers for given sequence of integer numbers such that after raising them to the M-th power they will be divided by K.解法:注意到每个数不超10000,这个题就沦为水题了。求质数,

2014-01-30 15:23:57 1182

原创 SGU116 动态规划 DP

问题:超级质数是在质数序列中下标也是质数的质数,例如3,5,11……现在给你一个数,找一个由超级质数构成的最小表示使得这些数的和等于这个数。解法:先求出这些超级质数,然后就是个完全背包问题。具体可见我动态规划关于背包的文章。Problem: Super-prime number is such a prime number that its current number in prime

2014-01-29 22:54:17 1150

原创 DP:四边形不等式优化 Optimization of Quadrilateral Inequality

定义1:当决策代价函数w满足w[a, c]+w[b, d]满足四边形不等式。定义2:当函数w满足w[b, c]关于区间包含关系单调。如果状态转移方程dp[i, j] = min{dp[i, k-1]+dp[k, j]}+w[i, j](i且w满足四边形不等式,则有定理1:上式dp满足四边形不等式。定理2:令让dp[i, j]取最小值的k为K[i, j],则有K[i, j-1]定

2014-01-29 20:38:39 3708 5

原创 SGU115 水题 Too Easy

Problem: Write a program that finds the name of the day of the week for any date in 2001(Monday – number 1, … , Sunday – number 7).Solution: "Impossible" is important...#include #include using n

2014-01-28 22:03:29 1103

原创 SGU114 水题 Easy Problem

题意:N个城市在坐标轴上,每个城市有坐标和人口。现设立一个广播站,每个城市的不满度是该城市人口与该城市到广播站距离的乘积。求广播站坐标使得各个城市不满度之和最小。Problem: Every city in Berland is situated on Ox axis. The government of the country decided to build new telecasting

2014-01-28 21:56:30 1379

原创 SGU113 水题 Easy Problem

问题:判断一个数是否是两个质数的乘积。Problem: Nearly prime number is an integer positive number for which it is possible to find such primes P1 and P2 that given number is equal to P1*P2. There is given a sequence on

2014-01-28 17:15:45 1161

原创 SGU112 水题 Easy

Problem: You are given natural numbers a and b. Find a^b-b^a.Solution: It is easy to solve in C++. More easier in Java!import java.util.Scanner;import java.math.BigInteger;import java.io.*;pub

2014-01-04 22:15:05 813

原创 SGU111 大数开方 Evolution

Problem: You are given natural number X. Find such maximum integer number that it square is not greater than X.(X.length解法:想用java水过但是跪了。上网查到了笔算开方,不过另一段短小的程序却更神奇。完全不会= 。=  于是收录在这里了。Solution: A smal

2014-01-04 22:11:55 1134 1

原创 SGU110 计算几何 Computational Geometry

题意:三维空间N个球体,给一个光束的方向,求它在这些球体间的反射情况(球面反射)。Problem: N spheres are in a 3D-space. Give you a direction of a light and write a program to output the reflections(the light rays reflect from the surface o

2014-01-04 22:03:06 1187

原创 SGU109 奇偶性 problem of parity

题意:N*N的方格,第一个人从1号格(左上)开始走K1步(上下左右),然后去掉他永远不可能走到的格子。第二个人接着第一个人的终点走K2步,再去掉他永远走不到的格子。以此类推,直到有一个人被困在唯一一个格子里。求给出K1到Ke,以及每次去掉了哪些格子(e是自己定的,符合题意就好)。Problem: Give you a N*N girds. The first person walks K1 s

2014-01-03 11:53:55 1049

原创 SGU108 数学题 Math

题目:一个数n,d(n)是n的各个位之和与它本身的和,比如d(35) = 35 + 3 + 5 = 43。n成为d(n)的产生数。现在给你一个数N和K,以及K个数Sk,问1-N有多少个自我数(没有产生数),以及第Sk个自我数是多少。Problem: For any positive integer n, define d(n) to be n plus the sum of the digit

2014-01-01 17:21:47 1132

原创 SGU107 水题 Easy

Problem: For given number N you must output amount of N-digit numbers, such, that last digits of their square is equal to 987654321.解法:编个程找规律,然后直接写。Solution: Write a program to find the rules then

2014-01-01 17:02:40 840

原创 SGU106 Extend GCD

题意:给出方程ax + by + c = 0,以及a,b,c,x1,x2,y1,y2, 问有多少整数解(x,y)满足x1    Problem:There is an equation ax + by + c = 0. Given a,b,c,x1,x2,y1,y2 you must determine, how many integer roots of this equation are

2013-11-23 11:14:29 814

原创 SGU105 水题 An easy problem

题意:这样的序列1,12,123,1234,...,12345678910,..问前N个元素和能否被3整除。    Problem:There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Given first N elements of that sequence. You must determine amount of nu

2013-11-23 10:36:03 894

原创 SGU104 DP

题意:N行M列的格子,每个格子有一些分值(可能为负),每行取一个格子,使得选取的总分值最大。要求每行所取的格子的列号严格大于上一行。    Problem:Give you a matrix of N rows and M columns, each grid has a value(maybe negative). You pick only one grid in each row to

2013-11-23 10:31:19 745

原创 SGU103 最短路 Shortest Path

题意:一个带权无向图,每个点有一个只有两种颜色的指示灯,每个灯初始颜色维持一定时间T1后变色,之后经过T2时间变色、T3时间变色、T2时间再变……成周期。一条边只有两个端点的指示灯颜色相同时才能通过,否则要等到相同。问从1到N的最短时间花费以及路径方案。    Problem:Give you a weighted undirected graph, each node has a traff

2013-11-20 22:48:54 1077

原创 SGU102 水题 An easy problem

题意:多少个不大于N的正整数与N互质。    Problem:For given integer N (1N104) find amount of positive numbers not greater than N that coprime with N. Let us call two positive integers (say, A and B, for example) cop

2013-11-20 22:17:11 1006

原创 SGU101 DFS

题意:给你一些Domino,两端有数字,问能否用全部骨牌首尾相连成一条链,使得相连的两端数字相同。可以的话要给出方案。    Problem:Give you some dominoes which have numbers on it's both sides. Can you connect the dominoes one by one to form a chain? It requi

2013-11-20 22:11:34 860

原创 C++:类与对象入门 Intro to Class and Object

我感觉已经很久都没有写过工程相关的东西了,大一学的C++的知识几乎都要忘光了。考虑到还有半年就毕业,我想抓紧最后的时间,再把之前的东西好好看看,在这个博客上简短的记录一些。不仅仅是C++,JAVA、编译、数据库、OS的东西我也会写一些东西放到这里。    作为C++回忆的开始,我打算从类和对象的一些简单知识入手。    先看如下的代码。//Book.h#pragma once#in

2013-11-20 11:52:47 1139

原创 Codeforces Round #213 (Div. 2)

昨天打了人生第一场CF,感觉挺有意思的。没想到Rank112就加了212分直接紫名了,好高兴。本来应该打的更好的,第一题开始没理解题意,看了announcement才懂的,耽误了不少时间,第二题忘了1的情况,第三题忘了0的情况。最后时间不多,加上第四题一直没什么思路,就进入了Hack的节奏,没想到错了三发,郁闷。三道题题意就不多说了,直接上代码。    第一题:水。#include #i

2013-11-20 10:25:11 989

原创 DP:背包问题 Knapsack Problem

背包问题非常适合动态规划的初学者。    首先我们适当讨论下动态规划。采用动态规划方法解决最优化问题的两个基本要素,是最优子结构和重叠子问题。    如果一个问题最优解包含了子问题的最优解,称其具有最优子结构。DP以自底向上的方法利用最有子结构,即先找子问题最优解,再找当前问题最优解。问题解代价为子问题代价与转移代价。DP与贪心的区别在于,DP根据子问题最优解进行转移,而贪心直接转移,属于

2013-11-19 18:52:04 3350

空空如也

空空如也

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

TA关注的人

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