- 博客(24)
- 收藏
- 关注
原创 UVa 10258 Contest Scoreboard
#include #include #include typedef struct team{ int id; int ac; int time; int vis; int acid[11]; int penalty[11];} Team;int cmp(const void *a,const void *b){ Tea
2014-05-12 14:52:31
501
原创 UVa 10044 Erdos Numbers
#include #include #include #include #define MAXNAME 500#define MAX 5000#define INFINITY -1typedef int elemType;typedef struct node{ elemType data; struct node *next;} Node;typedef struct
2014-05-09 11:20:55
517
原创 UVa 10205 Stack 'em Up
#include #include #define CARDNUM 52char Values[13][10] = { "2","3","4","5","6","7","8","9","10","Jack","Queen","King","Ace"};char Suits[4][10] = {"Clubs","Diamonds","Hearts","Spades"};void di
2014-05-02 00:38:11
406
原创 UVa 843 Crypt Kicker
#include #include #include char Keys[1000][16];char Words[40][16];char Cipher[26];char Trys[26];int KeyNum;int WordNum;/*int compare(char* a, char* b){ return strlen(a) > strlen(b) ? 1
2014-04-29 22:45:13
752
原创 UVa 10050 Hartals
#include int Days;int PoliticalNum;int Hartal[100];int countHartalsDays(){ int count = 0; int i,j; for(i=1;i<=Days;i++) { if(i%7==6 || i%7==0) continue; for(j=0;j<PoliticalNum;j++) {
2014-04-25 10:34:25
611
原创 UVa 10315 Poker Hands
#include #define NCARDS 52#define NSUITS 4char Values[] = "23456789TJQKA";char Suits[] = "CDHS";#define HIGH_CARD 1#define PAIR 2#define TWO_PAIRS 3#define THREE_OF_A_KIND 4#define STRAIGHT
2014-04-24 15:20:25
505
原创 堆排序
#include void swap(int &a,int &b){ int temp; temp = a; a = b; b = temp;} //µ÷Õû¶Ñ£¬±£³Ö×î´ó¶ÑµÄÐÔÖÊ void HeapAdjust(int *array,int i,int length){ int lchild = 2*i; int rchild = 2*i+1; int
2014-04-17 13:57:02
334
原创 UVa 10038 Jolly Jumpers
#include #include int Array[3000];int jolly(int length){ int i,temp; int filter[3000]={0}; for(i=0;i<length-1;i++) { temp = Array[i+1]-Array[i]; if(temp<0) temp = -temp; if(temp=length |
2014-04-16 14:33:32
378
原创 UVa 10142 Australian Voting
#include #include #include char Candidates[20][80];int Votes[1000][20];void elect(int num,int voteNum){ int Eliminate[20]; int Count[20]; int left,allvotes; int i,j; int min,max; left = n
2014-04-14 15:56:06
474
原创 UVa 10196 Check the Check
#include #include #include char ChessBoard[8][8];char *WhiteCheck = "white king is in check.";char *BlackCheck = "black king is in check.";char *NoCheck="no king is in check.";int boundary(int
2014-04-10 18:48:55
615
原创 UVa 10033 Interpreter
#include #include #include int Cache[1000];int Reg[10];int execute(){ int steps=0; int pc=0,ir=0; int a,b,c; while(ir!=100 && pc<1000) { ir = Cache[pc]; a = ir/100; b = (ir/10)%10;
2014-04-09 18:03:08
480
原创 UVa 10267 Graphical Editor
#include #include #define MAXSIZE 251char IMAGE[MAXSIZE][MAXSIZE];void display(int m,int n){int i,j;for(i=1;i{for(j=1;j{printf("%c",IMAGE[i][j]);}printf("\n");}}void L(
2014-04-04 10:59:42
418
原创 UVa 706 LC-Display
#include char NUMDISPLAY[5][10][4] = { " - ", " ", " - ", " - ", " ", " - ", " - ", " - ", " - ", " - ", "| |", " |", " |", " |", "| |", "| ", "| ", " |", "| |", "| |", "
2014-04-01 10:43:54
507
原创 UVa 10137 The Trip
#include double computeChange(double money[],int length){ double result,average,sum,changeDown,changeUp; int i; result = average = sum = changeDown = changeUp = 0.00; for(i=0; i<length; i++) s
2014-04-01 10:35:41
319
原创 UVa 10189 Minesweeper
#include int main(){ int i,j; int m,n; int field=0; char array[100][100]; int result[100][100]; int count=0; int row; int line; while(scanf("%d %d",&n,&m)){ if(m==0&&n==0) break; for(i=
2014-03-26 09:58:41
403
原创 UVa 100 The 3n + 1 problem
// [问题描述] // 考虑如下的序列生成算法:从整数 n 开始,如果 n 是偶数,把它除以 2;如果 n 是奇数,把它乘 3 加 // 1。用新得到的值重复上述步骤,直到 n = 1 时停止。例如,n = 22 时该算法生成的序列是: // // 22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1 // // 人们猜想(没有
2014-03-26 09:56:28
452
原创 分治法求m的n次方
int power(int m,int n){ if(n==1) return m; else if(n%2==1){ return m*power(m,(n-1)/2)*power(m,(n-1)/2); }else{ return power(m,n/2)*power(m,n/2); }}
2014-03-19 15:20:56
1248
原创 最大子数组
//基础解法:O(n*n) int maxSubSum(int array[],int length){ int i,j,sum=0,temp; for(i=0;i<length;i++) { temp=0; for(j=i;j<length;j++) { temp += array[j];
2014-03-19 15:19:17
389
原创 冒泡排序
void bublleSort(int array[],int length){ int i,j,temp; int flag; for(j=0;j<length-1;j++){ flag = 1; for(i=0;i<length-1-j;i++){
2014-03-19 15:18:45
330
原创 二分插入排序
void twoInsertSort(int array[],int n){ int left,right,num; int middle,j,i; for(i = 1;i < n;i++) { left = 0; right = i-1; num = array[i];
2014-03-19 15:17:06
376
原创 归并排序
void merge(int array[],int first,int last,int mid){ int array_temp[10]={0}; int i=first,j=mid+1,k; for(k=0;k<=last-first;k++) { if (i==mid+1) { array_temp[
2014-03-19 15:15:48
326
原创 简单选择排序
void selectSort(int array[],int length){ int i,j,temp,index; for(i=0;i<length-1;i++) { index = i; for(j=i+1;j<length;j++) { if(array[j]<array[in
2014-03-19 15:15:11
327
原创 直接插入排序
void insertSort(int array[],int length){ int i,j,key; for(i=1;i<length;i++) { key=array[i]; j=i-1; while (j>=0 && array[j]>key) { array[j+1]=a
2014-03-19 15:14:42
435
原创 两个n位二进制数相加
题目有两个各存放在数组A和B中的n位二进制整数,考虑他们的相加问题。两个整数的和存放在有n+1个元素的数组C中,请给出这个问题的形式化描述,并给出伪代码。void binaryAdd(int a[],int b[], int c[], int n){ int i,key,flag=0; for(i=0; i<n; i++) { key
2014-03-19 15:10:40
1479
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人