04 2012 档案
摘要:删除VMWare虚拟机安装目录下面的所有的*.lck目录,再重新启动OK
阅读全文
摘要:http://ac.jobdu.com/problem.php?id=1140 DFS,深度搜索时,从第一行到第8行,用col[i]记录第i行的皇后放的位置(也就是第几列)。View Code 1 #include<iostream> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 #include<vector> 6 #define N 8 7 using namespace std; 8 bool mat[N+1][N+1]; 9 int col[N+1]
阅读全文
摘要:http://poj.org/problem?id=1321 dfsView Code 1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 char mat[10][10]; 5 bool col[10];//col[i]=true表示第 i列有放 6 int n,k,solution=0; 7 int num;//当前放了几个 8 void initMat() 9 {10 memset(col,false,sizeof(col));11 solution=0;12 num=0;13 }14
阅读全文
摘要:http://poj.org/problem?id=2488 【DFS 】 一个p*q的棋盘,从一个点开始,骑士每次漫游都会在一个方向移动两个格子,并在垂直的方向移动一个格子。问题是,有没有这样一种漫游方法,每次骑士经过的地方都不同并且能够遍历整个棋盘?.要求 lexicographically first path,就是字典需最靠前的路径,这个就需要选择两个探测增量的时候考虑一下。先优先x后优先y,所以 int dx[]={-2,-2,-1,-1,1,1,2,2}; int dy[]={-1,1,-2,2,-2,2,-1,1};//保证路径按字典序,搜索时应自左向右,自上而下View Cod
阅读全文
摘要:http://poj.org/problem?id=2186 n头奶牛,给出若干个欢迎关系a b,表示a欢迎b,欢迎关系是单向的,但是是可以传递的。另外每个奶牛都是欢迎他自己的。 求出被所有的奶牛欢迎的奶牛的数目tarjan处理连通分量,每个连通分量缩点得到一个有向无环图DAG,若这个DAG只有一个点的出度为0,则该点代表的连通分量所含有的节点数,就是所求。View Code 1 #include<iostream> 2 #include<vector> 3 #include<cstring> 4 #include<cmath> 5 #inclu
阅读全文
摘要:http://ac.jobdu.com/problem.php?id=1418 强连通分量tarjan+dfsView Code 1 #include<iostream> 2 #include<vector> 3 #include<cstdio> 4 #include<cmath> 5 #include<stack> 6 #include<cstring> 7 using namespace std; 8 const int N=100008; 9 vector<int>mat[N];//原图 10 vecto
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1116 将每一个单词的首尾字母当做结点,首尾字母间连线,判断最后形成的有向图能否形成欧拉通路。欧拉通路:除首尾结点外,其余结点入度等于出度,起点出度减入度等于1,终点入度减出度等于1。欧拉回路:所有结点的入度都等于出度。View Code 1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 using namespace std; 5 const int N=30; 6 int father[N],i
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1108View Code 1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 int gcd(int a1,int b1)// 5 { 6 int a=max(a1,b1); 7 int b=min(a1,b1); 8 int temp=a%b; 9 while(temp!=0)10 {11 a=b;12 b=temp;13 temp=a%b;14 ...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1106 简单View Code 1 #include<iostream> 2 #include<cstring> 3 #include<vector> 4 #include<cstdlib> 5 #include<algorithm> 6 using namespace std; 7 vector<int>v; 8 void fun(string s)//分离数值到向量 9 {10 v.clear();11 int i,len=s.len
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1102 如果两个城市之间有边,则把其置为0,然后直接最小生成树,记录总距离。View Code 1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 const int N=108; 5 int mat[N][N]; 6 int dis[N]; 7 bool visited[N]; 8 int n; 9 int find()//在dis中找没访问的值最小的 10 {11 int pos=-1,minx=999
阅读全文
摘要:View Code 1 OJ上的一些水题(可用来练手和增加自信) 2 (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094) 3 初期: 4 一.基本算法: 5 (1)枚举. (poj1753,poj2965) 6 (2)贪心(poj1328,poj2109,poj2586) 7 (3)递归和分治法. 8 (4)递推. 9 (5)构造法.(poj3295) 10 (6)模拟法.(poj1068,...
阅读全文
摘要:http://ac.jobdu.com/problem.php?id=1036 暴力View Code 1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int n,x,y,z; 6 while(cin>>n) 7 { 8 cin>>x>>y>>z; 9 int i,j,temp,val,a,b;10 temp=x*1000+y*100+z*10;11 bool flag=false;12 for(i=9;i>0 && !f...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1076View Code 1 #include<iostream> 2 using namespace std; 3 bool isleap(int year) 4 { 5 if(year%4==0 && year%100!=0) return true; 6 if(year%400==0) return true; 7 return false; 8 } 9 int main()10 {11 int t,year,num;12 cin>>t;13 while(t-..
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1062 字符串反转,简单View Code 1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 using namespace std; 6 char line[1008]; 7 void reverse() 8 { 9 string temp;10 int i,len=strlen(line);11 for(i=0;i<len;i++)12 {
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1060 m=n^n;两边同取对数,log10(m)=n*log10(n); m=10^(n*log10(n))=(10^n)*(10^(n*log10(n))然后,对于10的整数次幂,第一位是1,所以,左边第一位数取决于n*log10(n)的小数部分View Code 1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 int main() 5 { 6 int n,t; 7 cin>>t; 8 wh
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1059 多重背包View Code 1 #include<iostream> 2 #include<cstring> 3 #include<cmath> 4 using namespace std; 5 int dp[120008]; 6 int num[7],total=0;// 7 bool dp1()//能装一半,返回true 8 { 9 memset(dp,0,sizeof(dp));10 int half=total/2;11 //cout<<&quo
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1056简单 模拟View Code 1 #include<iostream> 2 #include<cmath> 3 #include<cstring> 4 using namespace std; 5 int main() 6 { 7 double len; 8 while(cin>>len && len) 9 {10 double sum=1.0/2.0;11 if(sum>=len) {cout<<"1 card
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1051 先对length排序,再找出weight的递增序列(不一定连续) 个数View Code 1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 struct node 6 { 7 int x,y; 8 }; 9 node a[5008];10 bool flag[5008];11 int n;12 bool cmp(const node &
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1049 模拟题View Code 1 #include<iostream> 2 #include<vector> 3 #include<cstring> 4 #include<cstdlib> 5 using namespace std; 6 int main() 7 { 8 int n,u,d; 9 while(cin>>n>>u>>d)10 {11 if(n==0 && u==0 && d=
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1047 大数相加,没ACView Code 1 #include<iostream> 2 #include<vector> 3 #include<cstring> 4 #include<cstdlib> 5 using namespace std; 6 void add(string a,string b,string &sum) 7 { 8 sum=""; 9 int alen=a.length(),blen=b.length();
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1045 暴力搜索View Code 1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 using namespace std; 6 char mat[10][10]; 7 int n,maxx; 8 bool ok(int x,int y)//put here is ok 9 {10 if(mat[x][y]!='.') return
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1114背包View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 #define INF 99999999 7 struct node 8 { 9 int w;10 int v;11 };12 node a[508];13 int dp[10008];14 int n,sum;15 void s
阅读全文
摘要:http://ac.jobdu.com/problem.php?id=1395完全背包View Code 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 using namespace std; 5 int item[60]; 6 int dp[500008]; 7 int main() 8 { 9 int n;10 while(scanf("%d",&n)==1)11 {12 int i,j,sum=0;13 for(i=1;i<=n;i++) s
阅读全文

浙公网安备 33010602011771号