cjweffort

博客园 首页 联系 订阅 管理

2013年12月14日

摘要: maze_travel程序保证不会收集、存储、分享您的任何个人信息或者与您的设备相关的信息。我们不会收集任何统计数据和分析数据,也不会跟踪用户的行为。如果有问题请与我们联系。 阅读全文
posted @ 2013-12-14 18:11 cjweffort 阅读(109) 评论(0) 推荐(0) 编辑

2013年10月25日

摘要: //序列式容器1.vectortemplate class vector : protected _Vector_base {...}2.listtemplate class list : protected _List_base {...}3.slisttemplate class slist : private _Slist_base{...}4.dequetemplate class deque : protected _Deque_base{...}//适配器1.queuetemplate class queue {...}2.priority_queuetemplate ), ... 阅读全文
posted @ 2013-10-25 21:27 cjweffort 阅读(200) 评论(0) 推荐(0) 编辑

2013年10月14日

摘要: 题目限定数的范围N #include const int N = 100003; int ind[N]; int data[N]; int vol[N]; int ssize; int lowbit(int x){ return x & (-x); } void update(int pos, int inc){ while(pos 0){ ret += ind[pos]; pos -= lowbit(pos); } return ret; } //binarySearch the minimum value x that sum(x) = keyValue(the... 阅读全文
posted @ 2013-10-14 23:41 cjweffort 阅读(169) 评论(0) 推荐(0) 编辑

摘要: /*树状数组求解逆序对(1)对数据进行离散化(2)构建树状数组求解逆序对*/// poj2299逆序对_树状数组.cpp : 定义控制台应用程序的入口点。#include "stdafx.h"#include #include using namespace std;const int N = 500003;typedef struct Node{int value;int no;int tag;}Node;Node node[N], oriNode[N];int n;int sub[N];bool cmp1(Node m1, Node m2){return m1.valu 阅读全文
posted @ 2013-10-14 21:11 cjweffort 阅读(127) 评论(0) 推荐(0) 编辑

2013年10月10日

摘要: 01背包问题(1)排序数据为降序(2)背包处理// 1068. Find More Coins.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include #include #include #include using namespace std; #define max(a, b) ((a) > (b) ? (a) : (b)) const int N = 10003; int coin[N], dp[103]; vector ans[N]; typedef vector::iterator IT; typedef v 阅读全文
posted @ 2013-10-10 19:59 cjweffort 阅读(264) 评论(0) 推荐(0) 编辑

摘要: 好弱啊,这个题目折腾了好久。构造hash表用来维护各个元素所在的位置,利用map维护一颗红黑树来保存还未确定的元素的位置。(1)用0不断的跟其他元素交换,每次交换都会保证一个元素在正确的位置。(2)交换的过程中可能使得元素0到第0个位置,此时用0与某个还未在正确位置的元素交换。循环(1)(2)直至所有元素都在正确的位置。出现(2)这种情况的最大次数可能N,因为出现一次这种情况,一定会在接下来运行(1)的时候保证至少一个元素被交换到正确的位置。综上所述,最大交换次数应该不会高于2*N,每次交换会维护一次map,所以最终的算法复杂度应该为O(NlogN).// 1067. Sort with Sw 阅读全文
posted @ 2013-10-10 19:52 cjweffort 阅读(254) 评论(0) 推荐(0) 编辑

摘要: 这题挺有意思的// 1065. A+B and C (64bit).cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include using namespace std; int main() { long long a, b, c; int n; cin >> n; for(int i = 1; i > a >> b >> c; long long a1 = a / 3, b1 = b / 3, c1 = c / 3; long long a2 = a % 3, b2 = b % 3, 阅读全文
posted @ 2013-10-10 19:42 cjweffort 阅读(157) 评论(0) 推荐(0) 编辑

2013年7月7日

摘要: STL map的使用(红黑树)// QQ帐户的申请与登陆.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include #include #include using namespace std; map cmap; int _tmain(int argc, _TCHAR* argv[]) { int n; scanf("%d", &n); while(n--){ char cmdLine[3]; int id; char pwd[20]; scanf("%s%d%s", cmdLi 阅读全文
posted @ 2013-07-07 17:21 cjweffort 阅读(239) 评论(0) 推荐(0) 编辑

摘要: // 1060_Are_They_Equal.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include const int N = 303; void simplifyFloatNum(int n, char *str, int *dig, int &exp){ int len = strlen(str); bool tag = false; int firstNotZeroNum, pointNum; for(int i = 阅读全文
posted @ 2013-07-07 16:44 cjweffort 阅读(152) 评论(0) 推荐(0) 编辑

摘要: 筛素数法,分解因式// 1059_Prime_Factors.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include const int N = 31650; bool prime[N]; void selectPrime(){ prime[0] = prime[1] = true; for(int i = 2; i < N; i++){ if(!prime[i]){ for(int j = i * i; j < N; 阅读全文
posted @ 2013-07-07 16:43 cjweffort 阅读(166) 评论(0) 推荐(0) 编辑