上一页 1 ··· 6 7 8 9 10 11 下一页
摘要: 这道题主要是使用084的方法, 唯一要做的是处理一下输入 ,具体代码如下 复杂度O(n*n) 1 class Solution: 2 # @param {character[][]} matrix 3 # @return {integer} 4 def maximalRect... 阅读全文
posted @ 2015-07-06 07:49 dapanshe 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 这道题有两个做法 总体来说都是O(n) 但是第二个方法是第一个的简化版方法一:l[i] = max(j) 其中a[j], a[j+1], ...,a[i-1] a[i+1], ... ,a[j]dif[i] = r[i] - l[i]area[i] = a[i] * dif[i]最大的area[i... 阅读全文
posted @ 2015-07-06 07:32 dapanshe 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 暴力搜索 无压力, 只是要注意Line 14作用 如果用deepcopy则耗时多了好多 1 class Solution: 2 def __init__(self): 3 self.ans = [] 4 # @param {integer} k 5 # @pa... 阅读全文
posted @ 2015-07-04 13:06 dapanshe 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 我会说我直接用了 heapq这么无耻的方法吗 :) 这道题应该直观用heap 复杂度为O(nlgk)1 import heapq2 class Solution:3 # @param {integer[]} nums4 # @param {integer} k5 # @ret... 阅读全文
posted @ 2015-07-04 12:19 dapanshe 阅读(92) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;int visited[100001];int a[100001];int que[100001];int move[3][2] = {{1,-1},{1,1},{2,0}};int main(){ int n,k; cin>>n>>k; int front,rear,temp; int next; front = 0; rear = 1; a[front] = n; memset(visited,0,sizeof(visited)); memset(que,0,sizeof(qu 阅读全文
posted @ 2011-06-26 19:02 dapanshe 阅读(434) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;int a[20];int l[20];int r[20];int b[20];bool flag;int lcnt,rcnt;void calc(int n){ int i = 0; while(n/3) { a[i++] = n%3; n = n/3; } a[i] = n;}void balance(){ int i; for(i=0;i<20;i++) { if(a[i]==3){a[i+1]++;a[i]=0;} if(a[i]==2) { l[i] =1; a[i+1]++; a[i]= 阅读全文
posted @ 2011-06-23 15:15 dapanshe 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 终于写了个mergesort 偷懒不行啊#include <iostream>using namespace std;int a[500001];int temp[500001];__int64 sum;void merge(int l,int m,int r){ int p = 0; int i = l; int j = m+1; while(i<=m && j<=r) { if(a[i]>a[j]) { temp[p++] = a[j++]; sum += m-i+1; } else temp[p++] = a[i++]; } while(i& 阅读全文
posted @ 2011-06-17 21:19 dapanshe 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 用map比较容易 ,但是要注意没一个case都需要清空一下map 嗯这里贡献了一次Wa#include <iostream>#include <string>#include <map>using namespace std;int main(){ int test; int n; cin>>test; string str[400]; string str1,str2; int s; int cas=0; while(test--) { map<string,string>map1; map1.clear(); map<str 阅读全文
posted @ 2011-06-16 22:35 dapanshe 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 这题用cin 和cout 超时 悲催#include <iostream>#include <algorithm>using namespace std;int fact[5] = {1,1,2,6,24};int main(){ int a[1025]; int test; scanf("%d",&test); int i,j; while(test--) { int n,k; scanf("%d%d",&n,&k); i=0; if(n<5) k %= fact[n]; while(i<n) 阅读全文
posted @ 2011-06-16 21:44 dapanshe 阅读(266) 评论(0) 推荐(0) 编辑
摘要: set会自动排序,这个号省时间#include<iostream>#include<set>using namespace std;int main(){ set<long long>s; long long a[1510]; s.insert(1); int i; for(i=1;i<=1500;i++) { a[i] = *s.begin(); s.erase(s.begin()); s.insert(a[i]*2); s.insert(a[i]*3); s.insert(a[i]*5); } int n; while(cin>>n & 阅读全文
posted @ 2011-06-16 20:35 dapanshe 阅读(407) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 下一页