博文

浮点数精度问题(2007-09-04 19:52:00)

摘要: Exact Change Only Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB Problem 10838 : No special judgement Problem description Boudreaux reached over and shook awake Thibodeaux, who had dozed off somewhere in New Mexico. "Where we at?" Thibodeaux groggily yawned. "Not in Vegas, I gua-ran-tee, but could you get my knapsack?" Boudreaux asked, gesturing to the worn, leather backpack in the back seat of their cherry red Ford Miata. "Why, is there a problem?" "Just hand me my knapsack, problem or not." Thibodeaux complied, glancing up as Boudreaux slowed the car to a stop in a line of vehicles approaching a toll booth. "$1.65 -- Exact change only," Thibodeaux read the yellow sign on the front of a small wooden building occupied by a lone toll booth operator. "I have to get $1.65 in exact change?" Thibodeaux asked, digging through the knapsack, "all I have are ten quarters, four dimes, and three pennies. I don't have any nickels . . ......

阅读全文(3876) | 评论:0

分牌(2007-08-24 17:07:00)

摘要:描述 Description  
   有 N 堆纸牌,编号分别为 1,2,…, N。每堆上有若干张,但纸牌总数必为 N 的倍数。可以在任一堆上取若于张纸牌,然后移动。
  移牌规则为:在编号为 1 堆上取的纸牌,只能移到编号为 2 的堆上;在编号为 N 的堆上取的纸牌,只能移到编号为 N-1 的堆上;其他堆上取的纸牌,可以移到相邻左边或右边的堆上。
  现在要求找出一种移动方法,用最少的移动次数使每堆上纸牌数都一样多。   例如 N=4,4 堆纸牌数分别为:
  ① 9 ② 8 ③ 17 ④ 6
  移动3次可达到目的:
  从 ③ 取 4 张牌放到 ④ (9 8 13 10) -> 从 ③ 取 3 张牌放到 ②(9 11 10 10)-> 从 ② 取 1 张牌放到①(10 10 10 10)。
 
  
  
 输入格式 Input Format 
   N(N 堆纸牌,1 <= N <= 100)
A1 A2 … An (N 堆纸牌,每堆纸牌初始数,l<= Ai <=10000)  //// 真没想到这么简单 。。。。 #include <iostream>
using namespace std; int main(){
 int a[100],n,move,b,i,sum;
 cin>>n;
 for(sum=i=0; i<n; i++){
  cin>>a[i];
  sum+=a[i];
 }
 for(sum/=n,i=b=move=0; i<n; i++){
  if((a[i]+b) != sum){
   b+=(a[i]-sum);
   move++;
  }
&nbs......

阅读全文(2636) | 评论:0

Children of the Candy Corn (阅读理解)(2007-08-13 17:20:00)

摘要: Children of the Candy Corn Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB Total submit users: 29, Accepted users: 23 Problem 10833 : No special judgement Problem description The cornfield maze is a popular Halloween treat. Visitors are shown the entrance and must wander through the maze facing zombies, chainsaw-wielding psychopaths, hippies, and other terrors on their quest to find the exit. One popular maze-walking strategy guarantees that the visitor will eventually find the exit. Simply choose either the right or left wall, and follow it. Of course, there's no guarantee which strategy (left or right) will be better, and the path taken is seldom the most efficient. (It also doesn't work on mazes with exits that are not on the edge; those types of mazes are not represented in this problem.) As the proprieter of a cornfield that is about to be converted into a maze, you'd like to have a computer program that can dete......

阅读全文(4366) | 评论:0

Fibnacci string(题库)(2007-08-04 17:56:00)

摘要:Fibnacci string 
Problem description
The Fibnacci string is as follows:
S1=b
S2=a
Sk=Sk-1Sk-2 k>2
We are given a string, is there a Fibnacci string? Input
The input will consist of a series of string, one string per line, followed by a line containing only the char ‘0’ that signals the end of the input file and need not to be processed.
You may assume that the length of each string is no more than 1,000,000. Output
For each string you should output the ‘true’ if the string is a Fibnacci string, or ‘false’ if the string is not a Fibnacci string and with one line of output for each line in input.
 
Sample Input
abaab
abaababa
abaababaababa
0 Sample Output
true
true
false
 
//友情提示,请注意 a, b my code as followed :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char gstr[1000010],str[1000010];
int  gm[34];
void Init(){
 int t,i,j;
 for(i......

阅读全文(2885) | 评论:0

残缺数问题(2007-05-03 19:33:00)

摘要:// 这是QQ群里某网友提出的问题,贴出我的代码,我想应该找完了
/*  用 0,1,2,3,4,5,6,7,8,9 填写 [][][]+[][][]=[][][][] 使对应的加法正确。
** 首先可以确定 1 的位置[1][][][]因为每个数字只能用一次,所以每两个数字
** 相加如果所得结果模 10 后的数字或者加 1(有进位时)后的数字已经使用过
** 则这两个数不不能填在两个加数相同的位置上。
** 例如:2+3=5,如果取 2,3 时数字 5 没有使用则可以考虑将2 3 5这三个数填
** 入([][][2]+[][][3]=[1][][][5]) 代码如下:(主要用了递归的思想)
 */ #include <stdio.h>
#include <string.h> struct stack{      
 int a;       
 int b;        
 int c;
 int j;
}; struct stack stk[4] =  { 0 };
int          digit[] = { 0,1,2,3,4,5,6,7,8,9 }; void get(int d,int *status){
 int i,j,sum = 0,saveSum = 0;
 
 if(d == 3){
  if(stk[3].j == 1){
   printf( "%d%d%d+%d%d%d=1%d%d%d\n" ,
    stk[2].a,stk[1].a,stk[0].a,
 &nbs......

阅读全文(2491) | 评论:0

单词统计(2007-03-20 11:06:00)

摘要:/*
编写一个程序要求用户输入一段文字,然后按照每个单词的开头字母对这段文字分类统计单词的数量并排序输出。例如,一次运行程序情况如下:
Please input a passage:
The topic of this assignment is about array, pointer and string. In particular, the goal of the assignment is to give you experience for dividing programs into modules and using the pointer for manipulation of string data.
Words begin with t: 7
Words begin with a: 6
Words begin with i: 4
Words begin with p: 4
Words begin with o: 3
Words begin with d: 2
Words begin with f: 2
Words begin with g: 2
Words begin with m: 2
Words begin with s: 2
Words begin with e: 1
Words begin with u: 1
Words begin with y: 1 Total words: 37
 单词必须为字母开头
 以回车为输入结束标记
*/
#include <stdio.h>
#include <ctype.h> int main(){
    int i,j,k,max,flag = 0,sum = 0;
    int word[26];
    char c;     for (i = 0; i < 26; i++)
        word......

阅读全文(3459) | 评论:1

简单的(2007-03-20 10:56:00)

摘要:/* Problem Deion 8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天? Input 输入包括多个测试实例.每个测试实例包括2个整数M, k,(2 <= k <= M <= 1000).M = 0, k = 0代表输入结束. Output 对于每个测试实例输出一个整数,表示M元可以用的天数。 Sample Input
2 2
4 3
0 0
Sample Output
3
5 */ #include <stdio.h>
#include <malloc.h> typedef struct node{
    int m;
    int k;
    int d;
    struct node*next;
}NODE; int main(){
    NODE *head,*temp;     head = temp = (NODE*)malloc(sizeof(NODE));
    temp->d = 0;
    while(1){
        scanf("%d %d",&temp->m,&temp->k);
        if(!temp->m && !temp->k)
            break;
        else{
     &......

阅读全文(2655) | 评论:0