hdu 4351 Digital root多次范围查询
摘要:线段树,虽然没接触过也不太懂,但实用价值好像还蛮大的。View Code /*Sample Input15101 240 331 4 5231 34 51 5Sample OutputCase #1:8 7 6 4 27 4 2 -1 -19 8 7 6 4HintFor the first query, [1,3] has six subintervals: [1,1],[2,2],[3,3],[1,2],[2,3],[1,3]. Interval sums are 101,240,331,341,571,672, correspondence digital roots are 2,6,7
阅读全文
poj 2299 Ultra-QuickSort【树状数组】
摘要:求排序的数最少的交换次数。只能相邻的交换。归并排序算法:View Code #include<stdio.h>#include<limits.h>const int MAXN = 500000 + 10;const int INF = INT_MAX;long long tot;//tot为逆序数总数。int arr[MAXN];//将b数组中的元素复制到a数组中。void CopyArray(int a[], int b[], int len, int left){ for(int i = 0; i < len; i++) { a[left++] = b[i];
阅读全文
hdu 4350 card
摘要:当想出来只是求余的问题的时候就不难了。其实都不想发的。View Code #include<iostream>#include<stdio.h>using namespace std;int a[53],b[53];int main(){ int t,n,l,r,i,j; int s,w; cin>>t; int d=0; while(t--) { for(i=0;i<52;i++) cin>>a[i]; cin>>n>>l>>r; s=r-l+1; //...
阅读全文
hdu1285 确定比赛名次【拓扑排序】
摘要:关于拓扑排序特意找了个简单的做,呵呵。。。View Code #include <stdio.h>#include <string.h>#include <iostream>using namespace std;int a[551][501],ru[551];int main(){ int n,m,i,q1,q2,z,j,k; while(scanf("%d%d",&n,&m)!=EOF) { z=0; memset(a,0,sizeof(a)); memset(ru,0,sizeof(ru)); for(i=1; i.
阅读全文
poj1007 DNA排序
摘要:View Code #include <iostream>#include <algorithm>using namespace std;class DNA{public:char DNAString[51];int length;int measure;DNA(){ length=0; measure=0;}DNA(const DNA &a ){ length=a.length; measure=a.measure; for (int i=0;i<length;++i ) DNAString[i]=a.DNAString[i]; DNAString[le
阅读全文
acm hdu4325 Flowers(区间最大叠加数)
摘要:先展示一个我同学些的代码,超级goodView Code #include<iostream>#include<cstdio>#include<cstring>using namespace std;int C[150005];int B[150005];//int Out[150005];int N=150005;int Lowbit(int x){ return x&(-x);}void Modify(int i,int x){ while(i>0) { cout<<i<<" : "<<
阅读全文