Posts Tagged ‘算法’

May 23, 2009

Description:

There is a special card game that one who wins least rounds gets the money from people who win more. Suppose there are M people, including you, playing this game. First of all, each player gets N cards. The number on each card is a positive integer which is at most N*M. Additionally, the number of the cards is unique. The game consists of N rounds; for each round every player chooses one card to compare with cards from others. The player whose card with the biggest number wins the set, and then the next round begins. After N sets, when all the cards have been chosen, the player who has won the least rounds domains the game.

Tags: . 10 views
May 18, 2009

题目描述:

Felicia的LCD当然与众不同,她的显示器是有许多许多坏点的,此外,
她的显示器只能显示两种颜色(黑和白,分别对应亮与暗),显示器中任意相邻的点不能同时亮,
一次你遇到漂亮的Felicia,你被迷倒了,于是你想帮助她换一台新的LCD,
但她却考你能算出她的LCD一共能够显示出多少种不同的图案,
智慧的你能不能完成这个任务呢?

Tags: . 7 views
May 12, 2009

描述:

本程序可以将一个3000位的二进制串转化成十进制串

Tags: . 71 views
May 10, 2009

题目描述:

算出n!的完整结果,其中n!=1*2*3*…*n

输入:

多组测试数据,一行一组,每行仅一个数n
其中0<=n<=10000

输出:

输出相应的n!的结果,必须精确到个位

样例输入:

10
20
100

样例输出:

3628800
2432902008176640000
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

Tags: . 36 views

问题描述:

所谓子序列,就是在原序列里删掉若干个元素后剩下的序列,以字符串”abcdefg”为例子,去掉bde得到子序列”acfg”
现在的问题是,给你一个数字序列,你要求出它最长的单调递增子序列。

输入:

多组测试数据,每组测试数据第一行是n(1<=n<=10000),下一行是n个比1e9小的非负整数

输出:

对于每组测试数据输出一行,每行内容是最长的单调递增子序列的长度

样例输入:

5
1 2 4 8 16
5
1 10 4 9 7
9
0 0 0 1 1 1 5 5 5

样例输出:

5
3
3

Tags: . 49 views

题目描述:

给你一个数字,你要判断它是不是回文数字。例如134431或者242这种左右对称的数就叫做回文数。现在你需要编写一个Rev函数,其声明为int Rev(int n);
你需要判断输入的n是不是回文数字,如果是,请返回1,否则请返回0

样例输入:

123
12321

样例输出:

0
1

Tags: . 86 views
April 28, 2009

POJ 的一道题,算法很简单:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <string>
#include <iostream>
using namespace std;
 
int main()
{
    int n;
    char b2h[17] = "0123456789ABCDEF";
    int flag[4] = {1,2,4,8};
    cin>>n;
    while (n--)
    {
        string s;cin>>s;
        int len = s.length();
        int mod = len%4;
        int num = 0;
        for (int i=mod;i>0;i--)
        {
            if (s[mod-i]=='1')
            {
                num += flag[i-1];
            }
        }
        if (mod)
            cout<<b2h[num];
        for (int i=mod;i<len;i+=4)
        {
            num = 0;
            for (int j=0;j<4;j++)
            {
                if (s[i+j]=='1')
                {
                    num += flag[3-j];
                }
            }
            cout<<b2h[num];
        }
        cout<<endl;
    }
    return 0;
}
Tags: . 34 views
April 27, 2009

Description

A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = < x1, x2, ..., xm > another sequence Z = < z1, z2, ..., zk > is a subsequence of X if there exists a strictly increasing sequence < i1, i2, ..., ik > of indices of X such that for all j = 1,2,…,k, xij = zj. For example, Z = < a, b, f, c > is a subsequence of X = < a, b, c, f, b, c > with index sequence < 1, 2, 4, 6 >. Given two sequences X and Y the problem is to find the length of the maximum-length common subsequence of X and Y.

Tags: . 26 views
April 23, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
 
using namespace std;
//! declaration and implementation of class Matrix
class Matrix
{
	public:
		Matrix(int n = 2);
		Matrix(const Matrix& rf);
		int& operator [][](int x, int y);//! operator[][]
		int& operator [][](int x, int y) const;//! operator[][]const
		Matrix& operator *=(Matrix& rt);//! operator *=
	private:
		int *p_Matrix;//! pointer to the 2D array
		int m_n;//! dimension of the matrix
};
Tags: ,. 8 views
Page 4 of 41234