Search a 2D MatrixWrite an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row...
分类:
其他好文 时间:
2014-08-11 21:14:42
阅读次数:
179
假设有如下整数数组 -10 5 0 8 -1 10 -10 100 -1 求其最大的子序列和。从该数组我们可以知道其子序列和最大的序列为5 0 8 -1
10 -10 100且等于112。(为方便起见,如果数组全是负数则最大和为0)...
分类:
其他好文 时间:
2014-08-11 18:04:02
阅读次数:
243
题意:
给出一个迷宫,‘#’是墙壁,‘ ’(空格)可走,‘S’是起点,‘A’是目标,一个群体从S点开始,每次可以走周围相邻的4个格子,走到某个目标的花费是从上一个目标(或起点)开始计算的步数,群体可且仅可在S或A出分成若干个(可以看成是无数个,即使在同一个格子中)群体。比如从S开始走5步到A1,在A1分成两个群体,其中一个到达A2走3步,另一个到达A3也走3步,那么总花费是5+3+3=11。求到达所有A的最小花费。
分析:
题意很难理解,其实就是个最小生成树,用BFS在平面内模拟prim算法即可,这里要用到...
分类:
其他好文 时间:
2014-08-11 17:55:02
阅读次数:
268
题目大意:
一条街上有很多个餐厅,现在要在n个餐厅中选取m个作为仓库。
使得其他的餐厅到这些仓库的距离的和最小。
思路分析:
状态方程: dp [i] [j] 表示 前 j 个餐厅已经建了 i 个仓库。
转移方程: dp[i] [j] = min ( dp[i-1] [k] + cost[k+1][j] ) ...cost[ p ][ q ] 表示在p q 之间建立一个仓库...
分类:
其他好文 时间:
2014-08-11 15:05:12
阅读次数:
216
无锁编程以及CAS
无锁编程 / lock-free / 非阻塞同步
无锁编程,即不使用锁的情况下实现多线程之间的变量同步,也就是在没有线程被阻塞的情况下实现变量的同步,所以也叫非阻塞同步(Non-blocking Synchronization)。
实现非阻塞同步的方案称为“无锁编程算法”( Non-blocking algorithm)。
lock-free是目前最...
分类:
其他好文 时间:
2014-08-11 11:58:42
阅读次数:
321
#include #include using namespace std;int p1,p2,a[6],T;int main(){ scanf("%d",&T); while(T--){ for(int i=0;ip2)puts("Grandpa Shawn is the...
分类:
移动开发 时间:
2014-08-11 11:45:12
阅读次数:
203
1、用sort对结构体中字符串进行二级排序
#include
#include
using namespace std;
struct s
{
int d;
char c[10];
}ss[15];
bool cmp(s a,s b)
{
if(strcmp(a.c,b.c)!=0)
...
分类:
其他好文 时间:
2014-08-11 06:19:01
阅读次数:
171
1082. Read Number in Chinese (25)
时间限制
400 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
Given an integer with no more than ...
分类:
其他好文 时间:
2014-08-11 00:23:11
阅读次数:
256
http://acm.hdu.edu.cn/showproblem.php?pid=3221
一晚上搞出来这么一道题。。Mark。
给出这么一个程序,问funny函数调用了多少次。
我们定义数组为所求:f[1] = a,f[2] = b, f[3] = f[2]*f[3]......f[n] = f[n-1]*f[n-2]。对应的值表示也可为a^1*b^0%p,a^0*b^1...
分类:
其他好文 时间:
2014-08-11 00:22:51
阅读次数:
268
#include #include using namespace std;int main(){ int i,k,n,a[10000]; cin>>n; for(i=0;i>a[i]; sort(a,a+n); cout#include using name...
分类:
其他好文 时间:
2014-08-10 18:18:30
阅读次数:
162