摘要: 此题的本质问题就是对无向图的着色,使颜色使用最少的问题#include <stdio.h>#define maxn 27typedef struct Node{ int next[maxn]; int tot;}node;int main(){ int n; while(scanf("%d",&n)&&n!=0) { getchar();//吸收回车 node map[maxn]; int i,j,k; for(i=0;i<n;i++)//建图 { map[i].tot=0; getchar();//吸收每行的首字母,因为是字典序输 阅读全文
posted @ 2012-07-01 11:30 lishimin_come 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 直接暴力的#include <stdio.h>#include <string.h>#define maxn 21int matrix[maxn][maxn];int sel[maxn];int n;int max;int tot;void select(int cur){ if(cur==n) { if(tot==n||tot==0) return; int i,j; int amount=0; for(i=0;i<n;i++) { if(!sel[i]) continue; for(j=0;j<n;j++) { if(sel[j]) continue; 阅读全文
posted @ 2012-06-24 19:46 lishimin_come 阅读(100) 评论(0) 推荐(0) 编辑
摘要: bfs不解释#include <stdio.h>#define maxn 101int visit[maxn][maxn];int vol[2];//容量int c;int flag;typedef struct TNode//定义状态{ int cop[2]; int fa;//父节点 int dis;//距离 int op;//操作}Node;Node node[maxn*maxn];void printPath(int tem)//递归打印操作{ if(node[tem].op!=-1) printPath(node[tem].fa); if(node[tem].op!=-1 阅读全文
posted @ 2012-06-22 19:18 lishimin_come 阅读(113) 评论(0) 推荐(0) 编辑
摘要: hash#include <stdio.h>#include <memory.h>short hash[25000001];int main(){ int a1,a2,a3,a4,a5,x1,x2,x3,x4,x5; while(scanf("%d",&a1)!=EOF) { memset(hash,0,sizeof(hash)); int max=0; scanf("%d %d %d %d",&a2,&a3,&a4,&a5); int sum1; for(x1=-50;x1<=50; 阅读全文
posted @ 2012-06-16 20:13 lishimin_come 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 这道题wa了很多次,原因是PI的精度问题,精度一定很大#include <stdio.h>#define maxn 100010#define PI 3.14159265358979323846 int main(){ int amount; scanf("%d",&amount); while(amount--) { int n,f; scanf("%d%d",&n,&f); int i; double pie; double s[maxn]; double high=0; double low=0; for(i=0 阅读全文
posted @ 2012-06-15 21:05 lishimin_come 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 二分,至今仍不知为什么事单调关系,但是做此题之前,知道此题考查二分,所以就递增和递减都做了一下,最后发现是单调递增的;#include <stdio.h>#include <math.h>int main(){ double l,n,c; while(scanf("%lf %lf %lf",&l,&n,&c)) { if(l<0) break; double ll,ang; ll=(1+n*c)*l; double high=l;//为了保险定大一点 double low=0; double mid; while((hi 阅读全文
posted @ 2012-06-15 19:40 lishimin_come 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 解题方法:二分,因为移走石头的数目和最短的跳跃距离是单调关系,所以考虑用二分,并且一个距离可能有多个石头数目对应,表现在坐标图中就是一条平行于x轴的线段。还有关于代码中的二分的循环我想详细说明一下:high定位实际上界+1,是利用了左开右闭,这样的好处是当low=high时,区间中的元素就没有了,这样更易理解。因为肯定有解,所以经过循环low一定会等于当前解+1,然后寻找下一对于本题来说更优的解,所以到最后Low-1就是最后即最优的解;#include <cstdio>#include <algorithm>using namespace std;#define max 阅读全文
posted @ 2012-06-14 17:05 lishimin_come 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 二分,至今仍很纠结#include <stdio.h> #define maxn 100010 int n,m; int judge(int mid,int* ex) { int gr=1;//!!!!!!!!!!!! int sum=0; int i; for(i=0;i<n;i++) { if((sum+ex[i])<=mid) { sum+=ex[i]; } else { gr++; sum=ex[i];//!!!!!!!!!! } } if(gr>m) return 1;//说明小了 else return 0; } in... 阅读全文
posted @ 2012-06-13 18:30 lishimin_come 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 转载于http://www.cnblogs.com/yezhenhan/archive/2011/11/06/2238452.html语言位运算符:与、或、异或、取反、左移和右移位运算是指按二进制进行的运算。在系统软件中,常常需要处理二进制位的问题。C语言提供了6个位操作运算符。这些运算符只能用于整型操作数,即只能用于带符号或无符号的char,short,int与long类型。C语言提供的位运算符列表:运算符 含义 描述& 按位与 如果两个相应的二进制位都为1,则该位的结果值为1,否则为0| 按位或 两个相应的二进制位中只要有一个为1,该位的结果值为1^ 按位异或 若参加运算的两个二进 阅读全文
posted @ 2012-06-11 17:27 lishimin_come 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 哈希技术#include <stdio.h>#include <stdlib.h>#include <memory.h>#define maxn 1003typedef struct{ int x; int y;}Node;Node sq[1003];typedef struct THashTable{ int x,y; THashTable* next;}HashTable;HashTable* hash[maxn];void InsertHT(int i)//构建哈希表{ int key=(sq[i].x)*(sq[i].x)+(sq[i].y)*(sq 阅读全文
posted @ 2012-06-11 15:49 lishimin_come 阅读(133) 评论(0) 推荐(0) 编辑