| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1202 人关注过本帖
标题:[讨论]第一十八期编程题目--------大家继续加油哦
只看楼主 加入收藏
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
 问题点数:0 回复次数:11 
[讨论]第一十八期编程题目--------大家继续加油哦

第一题:
Oil Deposits

--------------------------------------------------------------------------------

Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 1412 Accepted Submit: 780

--------------------------------------------------------------------------------
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid.

Input

The input file contains one or more grids. Each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either `*', representing the absence of oil, or `@', representing an oil pocket.


Output

For each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.


Sample Input

1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0


Sample Output

0
1
2
2

翻译一下,上面的那个矩阵表示的是一块土地,@代表的是油,你的任务是找出土地上有多少快油,比如第一个例子只有一块是:
@ @
@
@ @ 要是翻译的不是很清楚,大家自己用金山,
提交地址:http://acm.zju.edu.cn/show_problem.php?pid=1709

第二
Sorting by Swapping
Time Limit:1000MS Memory Limit:10000K
Total Submit:2753 Accepted:1471

Description
Given a permutation of numbers from 1 to n, we can always get the sequence 1, 2, 3, ..., n by swapping pairs of numbers. For example, if the initial sequence is 2, 3, 5, 4, 1, we can sort them in the following way:

2 3 5 4 1
1 3 5 4 2
1 3 2 4 5
1 2 3 4 5

Here three swaps have been used. The problem is, given a specific permutation, how many swaps we needs to take at least.


Input
The first line contains a single integer t (1 <= t <= 20) that indicates the number of test cases. Then follow the t cases. Each case contains two lines. The first line contains the integer n (1 <= n <= 10000), and the second line gives the initial permutation.

Output
For each test case, the output will be only one integer, which is the least number of swaps needed to get the sequence 1, 2, 3, ..., n from the initial permutation.

Sample Input


2
3
1 2 3
5
2 3 5 4 1

Sample Output


0
3

翻译:求选择排序的时候交换的次数.注意排序的元素很特殊,他们是从1开始的连续的自然数序列!!!
提交地址:http://acm.pku.edu.cn/JudgeOnline/problem?id=1674
两个题目都不是很难,只要大家多动动脑筋一定都能做出来



[此贴子已经被作者于2007-6-9 9:52:02编辑过]

搜索更多相关主题的帖子: 加油 
2007-06-09 09:51
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

支持一下,落个沙发先.
大家做做吧.


倚天照海花无数,流水高山心自知。
2007-06-09 09:53
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
好久没有来了,沙发都没有占到,
大家注意第一个题目我可能翻译的不是很准确,

[此贴子已经被作者于2007-6-9 21:09:05编辑过]


2007-06-09 09:55
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1029
专家分:177
注 册:2007-5-10
收藏
得分:0 

程序代码:

//2007-06-09 13:51:32 Accepted 1709 C++ 00:00.00 880K lecoo
#include <iostream>
#include <assert.h>
using namespace std;

int adj_M[102][102];

int dx[]={0,0,1,-1,1,1,-1,-1};
int dy[]={1,-1,0,0,1,-1,1,-1};

void dfs(int x,int y)
{
for(int i=0;i<8;i++){
if(adj_M[x+dx[i]][y+dy[i]]=='@'){
adj_M[x+dx[i]][y+dy[i]]='*';
dfs(x+dx[i],y+dy[i]);
}
}
}

int main()
{
int m,n;
while(scanf(\"%d %d\",&m,&n)!=EOF && (m||n)){
assert(getchar()=='\n');
for(int i=0;i<=m+1;i++){
adj_M[i][0]='*';
}
for(int j=0;j<=n+1;j++){
adj_M[0][j]='*';
}
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
adj_M[i][j]=getchar();
}
assert(getchar()=='\n');
}

int cnt=0;
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
if(adj_M[i][j]=='@'){
cnt++;
adj_M[i][j]='*';
dfs(i,j);
}
}
}
printf(\"%d\n\",cnt);
}
}




//1674 Accepted 164K 62MS G++ 396B 2007-06-09 13:50:28
#include <iostream>
#include <algorithm>
using namespace std;

int arr[10001];

int main()
{
int N;
scanf(\"%d\",&N);
while(N--){
int n;
scanf(\"%d\",&n);
for(int i=1;i<=n;i++){
scanf(\"%d\",&arr[i]);
}
int cnt=0;
for(int i=1;i<=n;i++){
while(arr[i]!=i){
swap(arr[i],arr[arr[i]]);
cnt++;
}
}
printf(\"%d\n\",cnt);
}
}

2007-06-09 14:12
killer_l
Rank: 2
等 级:新手上路
威 望:3
帖 子:1139
专家分:0
注 册:2007-5-25
收藏
得分:0 
看看.......

2007-06-09 17:02
mp3aaa
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:2013
专家分:8
注 册:2006-2-15
收藏
得分:0 
哎呀 第一题 我只想出了 现用二维数组 然后在进行判断
不过这个方法感觉有点烂 还有人有更好的方法来做第一题吗? 把算法发出来看看啊

羊肉串 葡萄干 哈密瓜!!
2007-06-10 21:38
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 

第一个题目我和leeco的算法一样.都是DFS,时间都是0MS,空间多点400多K.
第二个有点不一样:
#include<stdio.h>
int main()
{
int t,n,a[10005],b[10005],sum,i,j,min,temp;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d",&a[i]),b[a[i]]=i;
sum=0;
for(i=1;i<=n;i++)
{
if(b[i]==i) continue;
else
{
b[a[i]]=b[i];
a[b[i]]=a[i];
sum++;
}
}
printf("%d\n",sum);
}
return 0;
}


2007-06-11 19:45
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
下期出题的任务.继续交给leeco

2007-06-11 19:46
hujian100
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2006-9-14
收藏
得分:0 

现在做题的人越来越少了,可能大家都很忙吧,抽空先做了一下第二题,第一题回头来做。
#include <stdio.h>
#include <stdlib.h>

void main()
{
int cyclenum, length;
int i, j, k, temp, count;
int *str;

printf( "Input the cycle number:" );
scanf( "%d", &cyclenum );

for( i = 0; i < cyclenum; i ++ )
{
printf( "Input the length of array:" );
scanf( "%d", &length );
printf( "Input the elements of array:" );
str = ( int * )malloc( sizeof( int ) * length );
for( j = 0; j < length; j ++ )
scanf( "%d", str + j );
count = 0;
for( j = 1; j <= length; j ++ )
{
k = j - 1;
if( str[k] == j )
continue;
else
{
for( k = j; k < length; k ++ )
{
if( str[k] == j )
{
temp = str[j - 1];
str[j - 1] = str[k];
str[k] = temp;
count++;
break;
}
}
}
}
free(str);
printf( "The least number of swaps is:%d.\n", count );
}
}


2007-06-12 16:10
xin520huan
Rank: 1
等 级:新手上路
帖 子:25
专家分:8
注 册:2007-4-25
收藏
得分:0 

学习学习


2007-06-12 17:23
快速回复:[讨论]第一十八期编程题目--------大家继续加油哦
数据加载中...
 
   



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

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