• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

╰☆惔、煙菋

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

2011年6月30日

找出数组中出现次数超过一半的数

摘要: 方法有很多,我就用两种最直接的方法实现一下方法一:比较法最容易想到的办法当然是直接用比较法,因为是超过一半,所以最多只能有一个,如果有多于一个的话就矛盾了时间复杂度O(N*N)空间复杂度O(N)public bool search(int nums[], int len, int & num){ int count; int length = len / 2 + 1; for (int i = 0; i < len; ++ i) { count = 1; for (int j = i+1; j < len; ++ j) { if (nums[i] == nums[j]) { 阅读全文

posted @ 2011-06-30 10:57 ╰☆惔、煙菋 阅读(310) 评论(0) 推荐(0)

2011年5月5日

HDU_3549 Flow Problem

摘要: 直接套模板#include <iostream>#include <queue>#define num 20#define max 10000#define min(a, b) a > b ? b : ausing namespace std;int n, m, t, f, map[num][num], pre[num];bool hash[num];void init(){ f = 0; memset(map, 0, sizeof(map)); cin >> n >> m; for (int i = 0; i < m; ++ i) 阅读全文

posted @ 2011-05-05 08:54 ╰☆惔、煙菋 阅读(1021) 评论(0) 推荐(0)

HDU_1532 Drainage Ditches

摘要: 很明显的最大流题目,通过不断寻找增广路,每找到一条就做相应的修改,直到找不到为止#include <iostream>#include <queue>#define max 100000000#define num 205using namespace std;int n, m, f;//map[][]记录权值,mark[]标记是否访问过,pre[]记录增广路 int map[num][num], mark[num], pre[num];void init(){ int a, b, c; memset(map, 0, sizeof(map)); f = 0; for ( 阅读全文

posted @ 2011-05-05 08:52 ╰☆惔、煙菋 阅读(810) 评论(0) 推荐(0)

2011年4月3日

HDU_2136 Largest prime factor

摘要: 刚开始时没考虑到时间问题,TLE 了好多次,刚开始是这样想的,先把素数筛出来,然后再找因为有几次TLE了,不得不换一种想法。在筛素数的时候就把相应素数的下表记下来,这样就省了好多时间下面贴代码#include<stdio.h> #include <string.h>#define max 1000000 int locat[max];int main(){ int i, j, n, m = 1; memset(locat, 0, sizeof(locat)); for (i = 2; i < max; ++ i) { if (locat[i]) continue; 阅读全文

posted @ 2011-04-03 11:47 ╰☆惔、煙菋 阅读(842) 评论(0) 推荐(0)

2011年4月2日

HDU_1878 欧拉回路

摘要: 做这题要分两步:1:先判断每个节点的度是否都为偶数,若都是偶数,则有可能存在欧拉回路,只要出现一个节点的度为奇数,则可以肯定绝对没有欧拉回路2:若所有节点的度都为偶数,再用并查集判断是不是从任意的节点走都可以走到其他的任意点,若可以则有欧拉回路,若不可以则没有#include <stdio.h>#define num 1000int m, n, i, a, b, flag, du[num], set[num];void init(){ for (i = 1; i <= n; ++ i) { du[i] = 0; set[i] = i; } flag = 0;}int find 阅读全文

posted @ 2011-04-02 20:47 ╰☆惔、煙菋 阅读(1103) 评论(0) 推荐(1)

HDU_1492 The number of divisors(约数) about Humble Numbers

摘要: 简单数论题 直接暴力算法#include <stdio.h>__int64 search(__int64 n, __int64 m){ __int64 sum = 0; while (n != 1) { if (n % m == 0) { sum ++; n /= m; } else break; } return sum;}int main(){ __int64 n, a, b, c, d, sum; while (scanf("%I64d", &n) && n) { a = b = c = d = 1; a += search(n, 阅读全文

posted @ 2011-04-02 15:18 ╰☆惔、煙菋 阅读(232) 评论(0) 推荐(0)

HDU_1299 Diophantus of Alexandria

摘要: 整数分解: 任何一个正整数都可以表示成素数的x次方之积,所以本题就被转化成了求n ^2的素因子个数; 先把n分解得到 n = p1^e1 * p2^e2 * ......*pr^er 其中p是< n 的素数那么n 的素因子, 则n的因子个数k =(e1 + 1) * (e2 + 1) * (e3 + 1)*...... 所以:n ^2的因子数是k = (2*e1+1) * (2*e2+1)* (2*e3+1)......这个题还要注意一点就是当n是素数的时候,很显然 k *= 3,这样做得到的结果是题目要求的2倍#include <stdio.h>#include <m 阅读全文

posted @ 2011-04-02 14:42 ╰☆惔、煙菋 阅读(1001) 评论(0) 推荐(0)

POJ_2485 Highways

摘要: 赤裸裸的最小生成树,直接prim算法解决#include <stdio.h>#define num 501#define INF 100000000int t, n, i, j, k, min, max, tmp, map[num][num], path[num];void prim(){ for (i = 2; i <= n; ++ i) { path[i] = map[1][i]; } path[1] = -1; max = 0; for (i = 1; i < n; ++ i) { min = INF... 阅读全文

posted @ 2011-04-02 12:12 ╰☆惔、煙菋 阅读(340) 评论(0) 推荐(0)

HDU_3786 找出直系亲属

摘要: 找出直系亲属Problem Description如果A,B是C的父母亲,则A,B是C的parent,C是A,B的child,如果A,B是C的(外)祖父,祖母,则A,B是C的grandparent,C是A,B的grandchild,如果A,B是C的(外)曾祖父,曾祖母,则A,B是C的great-grandparenet,C是A,B的great-grandchild,之后再多一辈,则在关系上加一个great-。Input输入包含多组测试用例,每组用例首先包含2个整数n(0<=n<=26)和m(0<m<50), 分别表示有n个亲属关系和m个问题, 然后接下来是n行的形式如A 阅读全文

posted @ 2011-04-02 10:55 ╰☆惔、煙菋 阅读(1243) 评论(0) 推荐(0)

2011年3月31日

HDU_1159 Common Subsequence

摘要: Common SubsequenceProblem DescriptionA subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, ..., xm> another sequence Z = <z1, z2, ..., zk> is a subsequence of X if there exists a strictly increasing sequence < 阅读全文

posted @ 2011-03-31 21:24 ╰☆惔、煙菋 阅读(441) 评论(0) 推荐(0)

下一页
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3