| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 749 人关注过本帖
标题:hello world----山东省第一届大学生acm竞赛中的水题,求解析
只看楼主 加入收藏
狂盗一枝梅
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2012-12-23
结帖率:0
收藏
 问题点数:0 回复次数:0 
hello world----山东省第一届大学生acm竞赛中的水题,求解析
Hello World!
Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^
题目描述
    We know that Ivan gives Saya three problems to solve (Problem F), and this is the first problem.
    “We need a programmer to help us for some projects. If you show us that you or one of your friends is able to program, you can pass the first hurdle.
    I will give you a problem to solve. Since this is the first hurdle, it is very simple.”
    We all know that the simplest program is the “Hello World!” program. This is a problem just as simple as the “Hello World!”
    In a large matrix, there are some elements has been marked. For every marked element, return a marked element whose row and column are larger than the showed element’s row and column respectively. If there are multiple solutions, return the element whose row is the smallest; and if there are still multiple solutions, return the element whose column is the smallest. If there is no solution, return -1 -1.
    Saya is not a programmer, so she comes to you for help
    Can you solve this problem for her?
输入
    The input consists of several test cases.
    The first line of input in each test case contains one integer N (0<N≤1000), which represents the number of marked element.
    Each of the next N lines containing two integers r and c, represent the element’s row and column. You can assume that 0<r, c≤300. A marked element can be repeatedly showed.
    The last case is followed by a line containing one zero.
输出
     For each case, print the case number (1, 2 …), and for each element’s row and column, output the result. Your output format should imitate the sample output. Print a blank line after each test case.
示例输入
3
1 2
2 3
2 3

0示例输出
Case 1:
2 3
-1 -1
-1 -1提示
 
来源
 
示例程序
 
这道题目是山东省第一届大学生acm竞赛中的题目,有人说是水题,但是我不会,有没有大神教教我这道题的思路,下面是这道题的代码,代码是别人的,我看不懂。
程序代码:
#include<stdio.h>
struct node
{
    int r;
    int c;
} g[1010],p[1010],t;
int main()
{
    int i,j,n;
    int o = 0;
    while(~scanf("%d",&n)&&n)
    {
        o++;
        for (i = 0; i < n; i ++)
        {
            scanf("%d%d",&g[i].r,&g[i].c);
            p[i].r = g[i].r;
            p[i].c = g[i].c;
        }
        printf("Case %d:\n",o);
        for (i = 0; i < n-1; i ++)
        {
            for (j = 0; j < n-1-i; j ++)
                if (p[j].r >= p[j+1].r)
                {
                    if (p[j].r==p[j+1].r&&p[j].c > p[j+1].c )
                    {
                            t = p[j];
                            p[j] = p[j+1];
                            p[j+1] = t;
                    }
                    if(p[j].r!=p[j+1].r)
                    {
                        t =  p[j];
                        p[j] = p[j+1];
                        p[j+1] = t;
                    }

                }
        }
        for (i = 0; i < n ; i ++)
        {
            for (j = 0; j < n; j ++)
            {
                if (g[i].r < p[j].r && g[i].c < p[j].c )
                {

                    printf("%d %d\n",p[j].r,p[j].c);
                    break;
                }

            }
            if (j == n)
                printf("-1 -1\n");
        }
        printf("\n");

    }
    return 0;
}

 

搜索更多相关主题的帖子: Memory 大学生 山东省 friends problems 
2013-06-04 21:17
快速回复:hello world----山东省第一届大学生acm竞赛中的水题,求解析
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021665 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved