【Lua】ElJudge 003 Contest Table
来源:互联网 发布:标准差算法 编辑:程序博客网 时间:2024/05/16 15:39
给出N个球队的比赛结果(胜负表),让排列出来一个“名次表”,保证这个“名次表”中,排在第i位的总是和在排在第i+1位的比赛中胜出
4#+#-+#-+-#SAMPLE OUTPUT:
1 3 4 2
算法就是搜索一下就可以了,很简单的
代码:
R=function() return io.stdin:read("*n") endcharAt=function(str,i) return string.sub(str,i,i) endlocal n=R()board,used,win={},{},{}_=io.read() --读入空行for i=1,n do board[i]=io.read() endfor i=1,n do used[i]=false endfor i=1,n do win[i]={} endfor i=1,n dofor j=1,string.len(board[i])-1 doif charAt(board[i],j)=='+' thenwin[i][j],win[j][i]=true,falseelse win[i][j],win[j][i]=false,trueendendendans={}t=0function find(k)if k==1 thenfor i=1,n doused[i]=trueans[k]=iif find(k+1) thenreturn trueendused[i]=falseendelseif k>n thenreturn trueelsefor i=1,n doif not used[i] and win[ans[k-1]][i] thenused[i]=trueans[k]=iif find(k+1) thenreturn trueendused[i]=falseendendendreturn falseendfind(1)print (table.concat(ans,' '))
注意:
1、变量命名时千万不要起table,虽然不是关键字,但是在调用table.concat时就出错了。。。找了半天。。。
2、table.concat可以引用table中的元素并在每个两个之间用给定的分割串隔开,效果等同于table[1]..table[2].. …… ..table[n]
0 0
- 【Lua】ElJudge 003 Contest Table
- 【Lua】ElJudge 004 Athletes
- 【Lua】ElJudge 002 Set Intersection
- 【Lua】ElJudge 000 Sum of two integers
- 【Lua】ElJudge 001 Max of Integers
- lua--table
- Lua table
- lua table
- 【Lua】table
- lua-table
- Lua #table
- Lua Table
- lua table
- [Lua] Lua print table
- 【Lua】Lua中的Table操作
- 【lua】Lua中的table函数库
- lua table note,table.sort ,table.concat
- LUA中的TABLE函数库
- c++子类父类的转换关系
- HDU 2046 骨牌铺方格。
- Pod::Executable pull
- xml -dom4j(一)
- 我的cocos2dx----常见错误:mt.exe : general error c101008d: Failed to write the updated manifest to the reso
- 【Lua】ElJudge 003 Contest Table
- xml-dom4j-xpath
- HDU 2018 母牛的故事。
- C++中ID、指针、handle (void *)的区别
- uva1508-Equipment 状态压缩 记忆化搜索
- 面向对象(二)
- 高级column family 配置
- Windows7系统安装Oracle11g R2图解
- Linux禁用IPv6