一道ACM题,求逆序对问题分治算法

背包问题类型各题总结-acm_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
喜欢此文档的还喜欢
背包问题类型各题总结-acm
阅读已结束,如果下载本文需要使用
想免费下载本文?
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢一道ACM的题,没看懂题目意思,请帮我大概解释一下_百度知道
一道ACM的题,没看懂题目意思,请帮我大概解释一下
//acm. After doing more research, he learned that the state of Louisiana is actually shrinking by 50 square miles each year.0Sample OutputProperty 1, he needs to know if his land is going to be lost to erosion. Z must be an integer. These will be floating point numbers measured in miles, including the capitalization.0 0.tju. Output FormatFor each data set. This includes the periods at the ends of /toj/vcontest/showp9050_F.025. Locations below the X axis are in the water. The Y coordinate will be non-negative. This semicircle is part of a circle centered at (0, Fred has learned that the land that is being lost forms a semicircle. Since Fred is hoping to live in this house the rest of his life./toj/vcontest/showp9050_F.edu.tju.Sample Input21.htmlFred Mapper is considering purchasing some land in Louisiana to build his house on.edu, and Z is the first year (start from 1) this property will be within the semicircle AT THE END OF YEAR Z;Where N is the data set (counting from 1): &quot. The semicircle has an area of 0 at the beginning of year 1.All locations are given in miles. In the process of investigating the land.&quot, and white-space. (Semicircle illustrated in the Figure, this should print out &quot.html" target="_blank">http: No property will appear exactly on the semicircle boundary, punctuation. Your answeProperty N.This problem will be judged automatically://acm: it will either be inside or outside, with the line that bisects the circle being the X axis, due to erosion caused by the Mississippi River. This line should take the form of. Each of the next N lines will contain the X and Y Cartesian coordinates of the land FNotes,0), a single line of output should appear.&END OF OUTPUT. After the last data set.) Input FormatThe first line of input will be a positive integer indicating how many data sets will be included (N): This property will begin eroding in year Z. (0,0) will not be given这是原题题目网址<a href="http.END OF OUTPUT: This property will begin eroding in year 1: This property will begin eroding in year 20.Property 2
提问者采纳
这个半圆形是一个以(0 ,并且是第一年(从1开始)此属性在半圆内:“属性N。每下一个N线将包含弗莱德想要的土地的(x。(半圆以数字说明,包括大小写,一个输出线应出现.0样例输出属性1。坐标是非负的,应打印出“结束输出.0 0:它要么是内部或外部,他需要知道自己的土地是否将会被侵蚀,到Z年底。这个半圆在第一年面积为0,表示多少数据集将包括在内(N)。是以英里计量的浮点数.025。)输入格式第一行输入将是一个正整数.0 1。属性2:此属性将开始侵蚀在Z年。所有的位置以英里为单位给出, 0)为圆心的圆的一部分。x轴的下方是在水中。因为弗莱德希望在这所房子里度过余生。(0 弗莱德考虑购买路易斯安那的土地来建造房子。”其中的数据集(从1)。在最后一组数据集之后。输出格式对于每个数据集,失去的土地形成一个半圆, 0)将不给予。这个问题会自动判断,x轴把圆一分为二。本线应采取的形式。这包括线末尾的部分,由于密西西比河的侵蚀,Z 必须是整数,他得知路易斯安那州正以每年50平方英里的速度收缩。结束输出:这个属性将会在第1年开始被侵蚀,标点符号和空格:无属性将出现在半圆上的边界上,y)笛卡尔坐标。样本输入21:这个属性将会在第20年开始被侵蚀,弗莱德了解到。你的回答必须完全匹配。”注。做了更多的研究。在调查过程中
意思知道了,但是样本输入21.0 1.025.0 0.0样例输出属性1:这个属性将会在第1年开始被侵蚀。属性2:这个属性将会在第20年开始被侵蚀。这个是根据什么判断出来时第几年开始被侵蚀的呢?
每年侵蚀50平方英里嘛,所以你就算那个点什么时候被侵蚀,也就是什么时候到x轴下面
没明白是怎样的一个侵蚀方式,这个50平方英里到底是怎么回事。。。比如侵蚀一次后,哪些坐标会被侵蚀了
提问者评价
其他类似问题
按默认排序
其他1条回答
;int main(){%lf %lf&*double ceil(double x),&count);i; return 0;/n&quot,y)到原点距离的半圆面积
然后再除50 取整
整理后公式就是 (x*x+y*y)*3; 功 能,y;2是求点(x.&#92;/ } printf(&quot: 返回大于或者等于指定表达式的最小整数*/}&#47.14/ scanf(&quot.&#92.14&#47,i+1;(x*x+y*y)*3;n&Property %d;
printf(&quot.h&;),(int)ceil((x*x+y*y)*3; for(int i=0;i++) {
scanf(&quot!=END OF OUTPUT;100)).h&#include &: This property will begin eroding in year %d.14&#47,&x;%d&stdio#include &lt,&y)
来自:求助得到的回答
acm的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁新手园地& & & 硬件问题Linux系统管理Linux网络问题Linux环境编程Linux桌面系统国产LinuxBSD& & & BSD文档中心AIX& & & 新手入门& & & AIX文档中心& & & 资源下载& & & Power高级应用& & & IBM存储AS400Solaris& & & Solaris文档中心HP-UX& & & HP文档中心SCO UNIX& & & SCO文档中心互操作专区IRIXTru64 UNIXMac OS X门户网站运维集群和高可用服务器应用监控和防护虚拟化技术架构设计行业应用和管理服务器及硬件技术& & & 服务器资源下载云计算& & & 云计算文档中心& & & 云计算业界& & & 云计算资源下载存储备份& & & 存储文档中心& & & 存储业界& & & 存储资源下载& & & Symantec技术交流区安全技术网络技术& & & 网络技术文档中心C/C++& & & GUI编程& & & Functional编程内核源码& & & 内核问题移动开发& & & 移动开发技术资料ShellPerlJava& & & Java文档中心PHP& & & php文档中心Python& & & Python文档中心RubyCPU与编译器嵌入式开发驱动开发Web开发VoIP开发技术MySQL& & & MySQL文档中心SybaseOraclePostgreSQLDB2Informix数据仓库与数据挖掘NoSQL技术IT业界新闻与评论IT职业生涯& & & 猎头招聘IT图书与评论& & & CU技术图书大系& & & Linux书友会二手交易下载共享Linux文档专区IT培训与认证& & & 培训交流& & & 认证培训清茶斋投资理财运动地带快乐数码摄影& & & 摄影器材& & & 摄影比赛专区IT爱车族旅游天下站务交流版主会议室博客SNS站务交流区CU活动专区& & & Power活动专区& & & 拍卖交流区频道交流区
空间积分0 信誉积分0 UID阅读权限10积分9帖子精华可用积分9 专家积分0 在线时间1 小时注册时间最后登录
白手起家, 积分 9, 距离下一级还需 191 积分
帖子主题精华可用积分9 专家积分0 在线时间1 小时注册时间最后登录
论坛徽章:0
本人系菜鸟,这两天做简单ACM联系题来提高对C语法的掌握
在杭电提交系统做题
然后对这个按说很简单的题的实现出现超时问题,而本人不能将其时间再缩短,苦恼中
这是原题的网页
其题意如下:
要求------Time Limit:
MS (Java/Others)& & Memory Limit:
K (Java/Others)
Total Submission(s): 5058& & Accepted Submission(s): 1487
我的1000多MS
Input contains multiple test cases. Each test case starts with a number N (0 & N &= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.
A test case with N = 0 terminates the input and this test case is not to be processed.
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
Sample Input5
Sample Output
下面是本人编的源码,可能漏洞很多,但能通过编译,运行没问题
#include &stdio.h&
#include &stdlib.h&
int issame(char[],char[]);
char str[1000][15];
int count[1000];
int main(int argc, char *argv[])
&&int n,i,j,max,
&&while(scanf(&%d&,&n)){
& & if(n==0)
& & max=0;
& & popular=0;& && && &
& & for(i=0;i&n;i++){
& &&&scanf(&%s&,&str);
& && && & }
& & for(i=0;i&n;i++){
& && &for(j=i+1;j&n;j++)
& && & if(issame(str,str[j]))
& && &&&count++;
& && &if(max&count){
& && & max=count;
& && & popular=i;
& && &}& && && && && && && &
& & printf(&%s\n&,str[popular]);
&&system(&PAUSE&);& && &&&
&&return 0;
int issame(char a[],char b[]){
& & for(i=0;a==b&&a!='\0';i++)
& & if(a==b&&a=='\0')
& &&&return 1;
& &&&return 0;
望高手指教如何缩短程序时间,感激不尽
&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp
空间积分0 信誉积分0 UID阅读权限10积分52帖子精华可用积分52 专家积分0 在线时间6 小时注册时间最后登录
白手起家, 积分 52, 距离下一级还需 148 积分
帖子主题精华可用积分52 专家积分0 在线时间6 小时注册时间最后登录
论坛徽章:0
你的结果是对的么?
如果结果是错的,时间缩短也没用
空间积分0 信誉积分0 UID阅读权限10积分9帖子精华可用积分9 专家积分0 在线时间1 小时注册时间最后登录
白手起家, 积分 9, 距离下一级还需 191 积分
帖子主题精华可用积分9 专家积分0 在线时间1 小时注册时间最后登录
论坛徽章:0
回复 #2 heavenstar_x 的帖子
结果和算法在正确性上没有任何问题,要不然系统会先报WRONG ANSWER
只是算法不够快,不知哪位高手有更快的算法可以解决这个问题
空间积分0 信誉积分0 UID阅读权限10积分52帖子精华可用积分52 专家积分0 在线时间6 小时注册时间最后登录
白手起家, 积分 52, 距离下一级还需 148 积分
帖子主题精华可用积分52 专家积分0 在线时间6 小时注册时间最后登录
论坛徽章:0
我记得如果是time out, 会在你程序结束前就会报出time out,
不会先报WRONG ANSWER。
sample的数据,你是否测试过。
[ 本帖最后由 heavenstar_x 于
02:42 编辑 ]
空间积分1 信誉积分130 UID8326155阅读权限20积分653帖子精华可用积分653 专家积分0 在线时间79 小时注册时间最后登录
丰衣足食, 积分 653, 距离下一级还需 347 积分
帖子主题精华可用积分653 专家积分0 在线时间79 小时注册时间最后登录
论坛徽章:0
issame(str,str[j])
这个编译不过的吧?
北京皓辰网域网络信息技术有限公司. 版权所有 京ICP证:060528号 北京市公安局海淀分局网监中心备案编号:
广播电视节目制作经营许可证(京) 字第1234号
中国互联网协会会员&&联系我们:
感谢所有关心和支持过ChinaUnix的朋友们
转载本站内容请注明原作者名及出处来 自:南京
等 级:新手上路
代码如下:
#include&stdio.h&
#include&string.h&
int main()
&&& char ch[10000],a;
&&& int i=0,k,n,m;
&&& memset(ch,'0',sizeof(ch));
&&& while(scanf(&%c&,&a)!=-1)
&&&&&&&&& while(a!='\n')
&&&&&&&&& {
&&&&&&&&&&&& ch[i++]=a;
&&&&&&&&&&&& if(a=='z') k=i-1;
&&&&&&&&&&&& else if(a=='j') n=i-1;
&&&&&&&&&&&& scanf(&%c&,&a);
&&&&&&&&&&&& }
&&&&&&&&&&&& m=i-1;
&&&&&&&&&&&& if((n-k-1==1)&&(k==m-n)) printf(&Accepted\n&);
&&&&&&&&&&&&
&&&&&&&&&&&& else if((n-k-1&=2)&&(m-n&=k)) printf(&Accepted\n&);
&&&&&&&&&&&&
&&&&&&&&&&&& else printf(&Wrong Answer\n&);
&&&&&&&&&&&&&&
&&&&&&&&&&&& i=0;
&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&return 0;
谢谢大家先!!
等 级:版主
威 望:87
帖 子:3097
专家分:12010
今天问ACM的人还真不少。
词法分析。我习惯自己先做一遍再回答,太晚了, 明天试试
重剑无锋,大巧不工
等 级:版主
威 望:87
帖 子:3097
专家分:12010
程序代码:#include&stdio.h&
int isAC(char * str)
&&& int i, zi, zn, ji, jn, a, b,
&&& for(zn = jn = i = <font color=#; str[i] != '<font color=#'; i++)
&&&&&&&&if(str[i] == 'z'){ zi = zn++;}
&&&&&&&&else if(str[i] == 'j'){ ji = jn++;}
&&& if(zn != <font color=# || jn != <font color=# || zi & ji) return <font color=#;
&&& for(a = <font color=#; *str == 'o'; str++, a++);
&&& for(str++, b = <font color=#; *str == 'o'; str++, b++);
&&& for(str++, c = <font color=#; *str == 'o'; str++, c++);
&&& if(b && a * b == c) return <font color=#;
&&& return <font color=#;
int main()
&&& char str[<font color=#1];
&&& while(scanf(&%s&, str) != EOF)
&&&&&&&&printf(&%s\n&, isAC(str) ? &Accepted& : &Wrong Answer&);
&&& return <font color=#;
重剑无锋,大巧不工
等 级:论坛游民
帖 子:31
专家分:42
以下是引用beyondyf在 07:43:54的发言:
int isAC(char * str)
&&& int i, zi, zn, ji, jn, a, b,
&&& for(zn = jn = i = 0; str != '\0'; i++)
&&&&&&&&if(str == 'z'){ zi = zn++;}
&&&&&&&&else if(str == 'j'){ ji = jn++;}
&&& if(zn != 1 || jn != 1 || zi & ji) return 0;
&&& for(a = 0; *str == 'o'; str++, a++);
&&& for(str++, b = 0; *str == 'o'; str++, b++);
&&& for(str++, c = 0; *str == 'o'; str++, c++);
&&& if(b && a * b == c) return 1;
&&& return 0;
int main()
&&& char str[1001];
&&& while(scanf(&%s&, str) != EOF)
&&&&&&&&printf(&%s\n&, isAC(str) ? &Accepted& : &Wrong Answer&);
&&& return 0;
研究了一上午加上3楼提供的程序才明白题目。
我的理解:
要求检验一组字符azbjc,其中在z,j字符固定不变,a,b,c为自然数。
满足一下条件的AC,否则WA。
1、a=0时,b=1,c=0;
2、a=1时,b=c;
3、a&1时,b=1,c=a.
不知是否有误?
等 级:版主
威 望:87
帖 子:3097
专家分:12010
回复 5楼 ljl123970
我代码中的a b c分别表示z之前o的数量、z与j之间o的数量,以及j之后o的数量
关于AC还有几个隐含条件,全部的条件如下:
1.串中z与j的数量必须为1
2.z的位置必须在j之前
3.b的数量至少为1
4.在b为1的情况下a必须等于c
5.在b大于1所情况下a必须等于b * c
重剑无锋,大巧不工
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
回复 6楼 beyondyf
杨大哥&&我怎么没读懂这个题呢&&&大哥帮我拿ozoojoo这个数据 分析一下它为啥符合第三个条件 谢啦
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
===========深入&-----------------&浅出============
等 级:论坛游民
帖 子:31
专家分:42
回复 6楼 beyondyf
漂亮!以b为第一条件,简洁明了,代码好看!服!!!!
——条件中第五条的a,c反了
代码中对的
向版主学习
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
回复 9楼 ljl123970
你读懂了&&拿ozoojoo这个数据 帮我解释下可以吗
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
===========深入&-----------------&浅出============
等 级:论坛游民
帖 子:31
专家分:42
回复 8楼 laoyang103
因为ozoojoo可以解读成:a=1,b=1,c=1;而此时azbjc就是ozojo满足第二个条件
我说的对吧
版权所有,并保留所有权利。
Powered by , Processed in 0.034625 second(s), 8 queries.
Copyright&, BCCN.NET, All Rights Reserved当前位置: >
> 一道ACM题目总是AC不了,求指出错误。。option=com_onlinejudge&I
一道ACM题目总是AC不了,求指出错误。。option=com_onlinejudge&I
waterlm & at
一道ACM题目总是AC不了,求指出错误。。 option=com_onlinejudge&Itemid=8&page=show_problem&category=108&problem=152&mosmsg=Submission+received+with+ID+
一道搜索题可以回溯也可以暴力枚举,我用的是暴力枚举,总是WA,样例都通过了,就是找不到原因,求大神指出错误,谢谢啦。
  #include&iostream&
#include&algorithm&
#include&iomanip&
#include&cstring&
#include&cmath&
using&namespace&
int&num[10];
int&num1[10];
&&&&int&x,y;
}point[10];
double&dis(int&len)
&&&&double&sum=0;
&&&&for(int&i=1;i&i++)
&&&&&&&&sum=sum+sqrt((point[num[i]].x-point[num[i-1]].x)*(point[num[i]].x-point[num[i-1]].x)+(point[num[i]].y-point[num[i-1]].y)*(point[num[i]].y-point[num[i-1]].y))+16;
&&&&return&
int&main()
&&&&int&n,k=0;
&&&&while(cin$>$n&&n)
&&&&&&&&memset(point,0,sizeof(point));
&&&&&&&&memset(num,0,sizeof(num));
&&&&&&&&memset(num1,0,sizeof(num1));
&&&&&&&&int&i,j;
&&&&&&&&for(i=0;i&n;i++)
&&&&&&&&&&&&cin$>$point[i].x$>$point[i].y;
&&&&&&&&for(i=0;i&n;i++)
&&&&&&&&&&&&num[i]=i;
&&&&&&&&double&minlen=dis(n);
&&&&&&&&while(next_permutation(num,num+n))
&&&&&&&&&&&&if(dis(n)&minlen)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&memcpy(num1,num,sizeof(num));
&&&&&&&&&&&&&&&&minlen=dis(n);
&&&&&&&&&&&&}
&&&&&&&&cout$<<$**********************************************************"$<$
&&&&&&&&cout$<<$Network&#"$<$++k$<$
&&&&&&&&for(i=1;i&n;i++)
&&&&&&&&&&&&double&d=sqrt((point[num1[i]].x-point[num1[i-1]].x)*(point[num1[i]].x-point[num1[i-1]].x)+(point[num1[i]].y-point[num1[i-1]].y)*(point[num1[i]].y-point[num1[i-1]].y));
&&&&&&&&&&&&cout$<<$Cable&requirement&to&connect&("$<$point[num1[i-1]].x$<<$,"$<$point[num1[i-1]].y$<<$)&to&("$<$point[num1[i]].x$<<$,"$<$point[num1[i]].y$<<$)&is&";
&&&&&&&&&&&&cout$<$fixed$<$setprecision(2)$<$d+16$<<$&feet."$<$
&&&&&&&&cout$<<$Number&of&feet&of&cable&required&is&"$<$fixed$<$setprecision(2)$<$minlen$<<$."$<$
&&&&return&0;
如果初始解是最优解的话你的num1全是0watermelon2008 & &
& & (0)(0)
本问题标题:
本问题地址:
温馨提示:本问题已经关闭,不能解答。
暂无合适的专家
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&&&湘教QS2-164&&增值电信业务经营许可证湘B2-}

我要回帖

更多关于 逆序对问题分治算法 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信