acm题,希望给出代码或思路.(效率高的)这个题是卡时间的

问题描述:

acm题,希望给出代码或思路.(效率高的)这个题是卡时间的
Description
Staginner ,the boss of A0A(Avoid 0 AC) Company,gives you a simple task,that is to calculate how many different points are there in the group of N points.
Input
There are several test cases.
The first line of each case contains a integer N(1
1个回答 分类:综合 2014-09-24

问题解答:

我来补答
这题其实非常的简单
题目中说了座标不大于1000的非负整数
可以开一个ext[1001][10001]的bool数组
每次输入一个点的时候ext[x][y]=true
最后统计一下哪些点是true的就行了,或者可以对所有的点进行排序,然后统计.不过这样的话编程有些麻烦
再问: 对啊!我比赛那天就是这样做的,但是超时了,不知道还有木有更优化的算法?? 你说的这个算法在统计的时候,时间复杂度是O(n*n)吧!这样超时了啊,估计只有O(n)能过。可能你说的这个还要优化剪枝后可能能过,但是我还没找到。
再答: 用排序,排序是nlogn的 题目地址在哪里啊?
再问: 你看下我补充的程序!!这个也是nlogn的,也超了。 这个是我们当时在局域网上的比赛,没有地址了。不好意思啊!
再答: 这样试试看 #include #include #include using namespace std; const int MAX=100005; int a[MAX]; int main(int argc, char *argv[]) { int i,n; int x,y; while(scanf("%d",&n)!=EOF) { for(i=0;i
 
 
展开全文阅读
剩余:2000
上一页:第九题,详解
下一页:gyyv