落絮飞雁

顺流而下,把梦做完

LastPass高级应用

写写LastPass 的高级技巧
READ MORE →

mdx词典的格式

时间过得很快。转眼……
READ MORE →

如何管理密码:[2]推荐一款密码管理软件LastPass

上一篇说到了高强度密码;这篇来介绍一款密码管理软件。
READ MORE →

致橡树——舒婷

好久没有更新了,转一首喜欢的诗歌~
READ MORE →

HDOJ1042:N!–大数

Problem Description
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!

Input
One N in one line, process to the end of file.

Output
For each N, output N! in one line.

Sample Input
1
2
3

Sample Output
1
2
6

要求计算10000以内的阶乘,典型的大数问题.这里用的是 五位一存的方法. 关于X位一存的解释可以看这篇文章. 注意特殊情况(0,1)下的处理.

#include 
#include 
#define MOD 100000
int main()
{
    int a[8000];    
    int i,k,n,t,la;
    while(~scanf("%d",&n))
    {
        if(n==0||n==1) {printf("1\n");continue;}

        a[0] = 1; 
        la = 1;
        t = 0;
        for(k=2; k 0)   
            {    
                a[la++] = t;
                t = 0; 
            } 
        }
        printf("%d",a[la-1]);
        for(i=la-2; i>=0; i--)
            printf("%05d",a[i]);
        printf("\n");
    }
    return 0;
}

HDOJ1052:Tian Ji — The Horse Racing–简单贪心

Here is a famous story in Chinese history.

“That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king and others.”

“Both of Tian and the king have three horses in different classes, namely, regular, plus, and super. The rule is to have three rounds in a match; each of the horses must be used in one round. The winner of a single round takes two hundred silver dollars from the loser.”

“Being the most powerful man in the country, the king has so nice horses that in each class his horse is better than Tian’s. As a result, each time the king takes six hundred silver dollars from Tian.”

“Tian Ji was not happy about that, until he met Sun Bin, one of the most famous generals in Chinese history. Using a little trick due to Sun, Tian Ji brought home two hundred silver dollars and such a grace in the next match.”

“It was a rather simple trick. Using his regular class horse race against the super class from the king, they will certainly lose that round. But then his plus beat the king’s regular, and his super beat the king’s plus. What a simple trick. And how do you think of Tian Ji, the high ranked official in China?”

Were Tian Ji lives in nowadays, he will certainly laugh at himself. Even more, were he sitting in the ACM contest right now, he may discover that the horse racing problem can be simply viewed as finding the maximum matching in a bipartite graph. Draw Tian’s horses on one side, and the king’s horses on the other. Whenever one of Tian’s horses can beat one from the king, we draw an edge between them, meaning we wish to establish this pair. Then, the problem of winning as many rounds as possible is just to find the maximum matching in this graph. If there are ties, the problem becomes more complicated, he needs to assign weights 0, 1, or -1 to all the possible edges, and find a maximum weighted perfect matching…

However, the horse racing problem is a very special case of bipartite matching. The graph is decided by the speed of the horses — a vertex of higher speed always beat a vertex of lower speed. In this case, the weighted bipartite matching algorithm is a too advanced tool to deal with the problem.

In this problem, you are asked to write a program to solve this special case of matching problem.

Input
The input consists of up to 50 test cases. Each case starts with a positive integer n (n 田忌最快的马比齐王最快的快–直接跑赢;

  • 田忌最快的马比齐王最快的慢–用田忌最慢的马去跟齐王的马跑;
  • 田忌最快的马跟齐王最快的一样快–再比较田忌最慢的马是否比齐王的最慢的马快,如果是就直接跑赢,如果不是就用田忌最慢的马去跟齐王最快的马跑.
  • 放上代码:

    #include
    #include
    #include
    int cmp(const void*a ,const void*b)
    {
    	return *(int *)b-*(int *)a;
    }
    int main()
    {
    	int i,n;
    	int tian,king;
    	int fa,fb,la,lb;
    	while(~scanf("%d",&n)&&n!=0)
    	{
    		int a[1001]={0},b[1001]={0};
    		getchar();
    		tian=king=0;
    		for(i=0;ib[fb])
    			{
    				tian++;
    				fa++;
    				fb++;
    			}
    			else if(a[la]>b[lb])
    			{
    				tian++;
    				la--;
    				lb--;
    			}
    			else if(a[la]b[fb])
    			tian++;
    		else if(a[fa]
    	

    HDOJ5131:Song Jiang’s rank list

    Problem Description
    《Shui Hu Zhuan》,also 《Water Margin》was written by Shi Nai’an — an writer of Yuan and Ming dynasty. 《Shui Hu Zhuan》is one of the Four Great Classical Novels of Chinese literature. It tells a story about 108 outlaws. They came from different backgrounds (including scholars, fishermen, imperial drill instructors etc.), and all of them eventually came to occupy Mout Liang(or Liangshan Marsh) and elected Song Jiang as their leader.

    In order to encourage his military officers, Song Jiang always made a rank list after every battle. In the rank list, all 108 outlaws were ranked by the number of enemies he/she killed in the battle. The more enemies one killed, one’s rank is higher. If two outlaws killed the same number of enemies, the one whose name is smaller in alphabet order had higher rank. Now please help Song Jiang to make the rank list and answer some queries based on the rank list.

    Input
    There are no more than 20 test cases.

    For each test case:

    The first line is an integer N (0<n&<200), indicating that there are N outlaws.

    Then N lines follow. Each line contains a string S and an integer K(0<k<300), meaning an outlaw’s name and the number of enemies he/she had killed. A name consists only letters, and its length is between 1 and 50(inclusive). Every name is unique.

    The next line is an integer M (0<m<200) ,indicating that there are M queries.

    Then M queries follow. Each query is a line containing an outlaw’s name.
    The input ends with n = 0

    Output
    For each test case, print the rank list first. For this part in the output ,each line contains an outlaw’s name and the number of enemies he killed.

    Then, for each name in the query of the input, print the outlaw’s rank. Each outlaw had a major rank and a minor rank. One’s major rank is one plus the number of outlaws who killed more enemies than him/her did.One’s minor rank is one plus the number of outlaws who killed the same number of enemies as he/she did but whose name is smaller in alphabet order than his/hers. For each query, if the minor rank is 1, then print the major rank only. Or else Print the major rank, blank , and then the minor rank. It’s guaranteed that each query has an answer for it.

    Sample Input
    5
    WuSong 12
    LuZhishen 12
    SongJiang 13
    LuJunyi 1
    HuaRong 15
    5
    WuSong
    LuJunyi
    LuZhishen
    HuaRong
    SongJiang
    0

    Sample Output
    HuaRong 15
    SongJiang 13
    LuZhishen 12
    WuSong 12
    LuJunyi 1
    3 2
    5
    3
    1
    2

    简单排序,直接上代码:

    #include
    #include
    #include
    #include
    using namespace std;
    #define N 205
    
    struct hero_t{
        string s;
        int i, n;
    } heros[N];
    
    struct node_t {
        int mmin, mmax;
        node_t() {}
        node_t(int a, int b) {
            mmin = a; mmax = b;
        }
    } node;
    
    //struct heros[N];
    
    bool comp(hero_t a, hero_t b) {
        if (a.n == b.n)
            return a.s  b.n;
    }
    
    int main() {
        int n, m;
        int i, j, k, id = 0;
        string s;
        node_t nd;
    
        while (cin>>n && n) {
            for (i=0; i>heros[i].s>>heros[i].n;
            }
    
            sort(heros, heros+n, comp);
            for (i=0; i tb;
            i = 0;
            while (i  1) {
                    for (k=0; k>m;
            while (m--) {
                cin >>s;
                nd = tb[s];
                if (nd.mmin == 1)
                    cout 
    	

    为wp-code-highlight添加新配色

    时隔近半年,终于把这个坑填上了……
    READ MORE →

    写写面试被问到的问题

    前一阵去几家公司面试暑期实习生。写写面试时被问到的几个问题。

    感谢各路大神(* ̄︶ ̄)y
    READ MORE →

    堪折直须折

    莫待无花空折枝……
    READ MORE →