文思海辉第一届在线编程大赛那个题

ghw554557313 2013-11-27 10:07:08
有没有大神参加了?
感觉好难的样子


题目详情

甲乙两个人用一个英语单词玩游戏。两个人轮流进行,每个人每次从中删掉任意一个字母,如果剩余的字母序列是严格单调递增的(按字典序a < b < c <....<z),则这个人胜利。两个人都足够聪明,甲先开始,问他能赢么?

输入: 一连串英文小写字母,长度不超过15,保证最开始的状态不是一个严格单增的序列。

输出:1表示甲可以赢,0表示甲不能赢。

例如: 输入 bad, 则甲可以删掉b或者a,剩余的是ad或者bd,他就赢了,输出1。

又如: 输入 aaa, 则甲只能删掉1个a,乙删掉一个a,剩余1个a,乙获胜,输出0。


函数头部:

C:int who (const char * word);

C++:int who (string word);

Java:public static int who(String in);

C# :public static int who(string word);
...全文
1898 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
霜之咏叹调 2013-12-25
  • 打赏
  • 举报
回复

引用 12 楼 yaofeng168 的回复:
输入字符串:abcdcabghwhgaha,字符串长度:15,无序度为6

开始递归移除字符串abcdcabghwhgaha,无序度为6,游戏进度,第1步
输入字符串:abcdcabghwhgaha,移除一个字符,得到的字符串列表:[bcdcabghwhgaha, acdcabghwhgaha, abdcabghwhgaha, abccabghwhgaha, abcdabghwhgaha, abcdcbghwhgaha, abcdcaghwhgaha, abcdcabhwhgaha, abcdcabgwhgaha, abcdcabghhgaha, abcdcabghwgaha, abcdcabghwhaha, abcdcabghwhgha, abcdcabghwhgaa, abcdcabghwhgah]
字符串bcdcabghwhgaha的无序度为6,详情:DisordeDegree [index=0, str=bcdcabghwhgaha, disordeDegree=6]
字符串acdcabghwhgaha的无序度为6,详情:DisordeDegree [index=1, str=acdcabghwhgaha, disordeDegree=6]
字符串abdcabghwhgaha的无序度为6,详情:DisordeDegree [index=2, str=abdcabghwhgaha, disordeDegree=6]
字符串abccabghwhgaha的无序度为6,详情:DisordeDegree [index=3, str=abccabghwhgaha, disordeDegree=6]
字符串abcdabghwhgaha的无序度为5,详情:DisordeDegree [index=4, str=abcdabghwhgaha, disordeDegree=5]
字符串abcdcbghwhgaha的无序度为6,详情:DisordeDegree [index=5, str=abcdcbghwhgaha, disordeDegree=6]
字符串abcdcaghwhgaha的无序度为6,详情:DisordeDegree [index=6, str=abcdcaghwhgaha, disordeDegree=6]
字符串abcdcabhwhgaha的无序度为6,详情:DisordeDegree [index=7, str=abcdcabhwhgaha, disordeDegree=6]
字符串abcdcabgwhgaha的无序度为6,详情:DisordeDegree [index=8, str=abcdcabgwhgaha, disordeDegree=6]
字符串abcdcabghhgaha的无序度为6,详情:DisordeDegree [index=9, str=abcdcabghhgaha, disordeDegree=6]
字符串abcdcabghwgaha的无序度为5,详情:DisordeDegree [index=10, str=abcdcabghwgaha, disordeDegree=5]
字符串abcdcabghwhaha的无序度为5,详情:DisordeDegree [index=11, str=abcdcabghwhaha, disordeDegree=5]
字符串abcdcabghwhgha的无序度为5,详情:DisordeDegree [index=12, str=abcdcabghwhgha, disordeDegree=5]
字符串abcdcabghwhgaa的无序度为6,详情:DisordeDegree [index=13, str=abcdcabghwhgaa, disordeDegree=6]
字符串abcdcabghwhgah的无序度为5,详情:DisordeDegree [index=14, str=abcdcabghwhgah, disordeDegree=5]
移除一个字符串后得到的字符串列表,返回最小无序度的字符串为:[DisordeDegree [index=4, str=abcdabghwhgaha, disordeDegree=5], DisordeDegree [index=10, str=abcdcabghwgaha, disordeDegree=5], DisordeDegree [index=11, str=abcdcabghwhaha, disordeDegree=5], DisordeDegree [index=12, str=abcdcabghwhgha, disordeDegree=5], DisordeDegree [index=14, str=abcdcabghwhgah, disordeDegree=5]]
移除字符串abcdcabghwhgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串:[DisordeDegree [index=4, str=abcdabghwhgaha, disordeDegree=5], DisordeDegree [index=10, str=abcdcabghwgaha, disordeDegree=5], DisordeDegree [index=11, str=abcdcabghwhaha, disordeDegree=5], DisordeDegree [index=12, str=abcdcabghwhgha, disordeDegree=5], DisordeDegree [index=14, str=abcdcabghwhgah, disordeDegree=5]]
移除字符串abcdcabghwhgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串,移除字符串:DisordeDegree [index=4, str=abcdabghwhgaha, disordeDegree=5]
移除字符串abcdabghwhgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串,移除字符串结果:abcdabghwhgaha

开始递归移除字符串abcdabghwhgaha,无序度为5,游戏进度,第2步
输入字符串:abcdabghwhgaha,移除一个字符,得到的字符串列表:[bcdabghwhgaha, acdabghwhgaha, abdabghwhgaha, abcabghwhgaha, abcdbghwhgaha, abcdaghwhgaha, abcdabhwhgaha, abcdabgwhgaha, abcdabghhgaha, abcdabghwgaha, abcdabghwhaha, abcdabghwhgha, abcdabghwhgaa, abcdabghwhgah]
字符串bcdabghwhgaha的无序度为5,详情:DisordeDegree [index=0, str=bcdabghwhgaha, disordeDegree=5]
字符串acdabghwhgaha的无序度为5,详情:DisordeDegree [index=1, str=acdabghwhgaha, disordeDegree=5]
字符串abdabghwhgaha的无序度为5,详情:DisordeDegree [index=2, str=abdabghwhgaha, disordeDegree=5]
字符串abcabghwhgaha的无序度为5,详情:DisordeDegree [index=3, str=abcabghwhgaha, disordeDegree=5]
字符串abcdbghwhgaha的无序度为5,详情:DisordeDegree [index=4, str=abcdbghwhgaha, disordeDegree=5]
字符串abcdaghwhgaha的无序度为5,详情:DisordeDegree [index=5, str=abcdaghwhgaha, disordeDegree=5]
字符串abcdabhwhgaha的无序度为5,详情:DisordeDegree [index=6, str=abcdabhwhgaha, disordeDegree=5]
字符串abcdabgwhgaha的无序度为5,详情:DisordeDegree [index=7, str=abcdabgwhgaha, disordeDegree=5]
字符串abcdabghhgaha的无序度为5,详情:DisordeDegree [index=8, str=abcdabghhgaha, disordeDegree=5]
字符串abcdabghwgaha的无序度为4,详情:DisordeDegree [index=9, str=abcdabghwgaha, disordeDegree=4]
字符串abcdabghwhaha的无序度为4,详情:DisordeDegree [index=10, str=abcdabghwhaha, disordeDegree=4]
字符串abcdabghwhgha的无序度为4,详情:DisordeDegree [index=11, str=abcdabghwhgha, disordeDegree=4]
字符串abcdabghwhgaa的无序度为5,详情:DisordeDegree [index=12, str=abcdabghwhgaa, disordeDegree=5]
字符串abcdabghwhgah的无序度为4,详情:DisordeDegree [index=13, str=abcdabghwhgah, disordeDegree=4]
移除一个字符串后得到的字符串列表,返回最小无序度的字符串为:[DisordeDegree [index=9, str=abcdabghwgaha, disordeDegree=4], DisordeDegree [index=10, str=abcdabghwhaha, disordeDegree=4], DisordeDegree [index=11, str=abcdabghwhgha, disordeDegree=4], DisordeDegree [index=13, str=abcdabghwhgah, disordeDegree=4]]
移除字符串abcdabghwhgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串:[DisordeDegree [index=9, str=abcdabghwgaha, disordeDegree=4], DisordeDegree [index=10, str=abcdabghwhaha, disordeDegree=4], DisordeDegree [index=11, str=abcdabghwhgha, disordeDegree=4], DisordeDegree [index=13, str=abcdabghwhgah, disordeDegree=4]]
移除字符串abcdabghwhgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串,移除字符串:DisordeDegree [index=9, str=abcdabghwgaha, disordeDegree=4]
移除字符串abcdabghwgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串,移除字符串结果:abcdabghwgaha

开始递归移除字符串abcdabghwgaha,无序度为4,游戏进度,第3步
输入字符串:abcdabghwgaha,移除一个字符,得到的字符串列表:[bcdabghwgaha, acdabghwgaha, abdabghwgaha, abcabghwgaha, abcdbghwgaha, abcdaghwgaha, abcdabhwgaha, abcdabgwgaha, abcdabghgaha, abcdabghwaha, abcdabghwgha, abcdabghwgaa, abcdabghwgah]
字符串bcdabghwgaha的无序度为4,详情:DisordeDegree [index=0, str=bcdabghwgaha, disordeDegree=4]
字符串acdabghwgaha的无序度为4,详情:DisordeDegree [index=1, str=acdabghwgaha, disordeDegree=4]
字符串abdabghwgaha的无序度为4,详情:DisordeDegree [index=2, str=abdabghwgaha, disordeDegree=4]
字符串abcabghwgaha的无序度为4,详情:DisordeDegree [index=3, str=abcabghwgaha, disordeDegree=4]
字符串abcdbghwgaha的无序度为4,详情:DisordeDegree [index=4, str=abcdbghwgaha, disordeDegree=4]
字符串abcdaghwgaha的无序度为4,详情:DisordeDegree [index=5, str=abcdaghwgaha, disordeDegree=4]
字符串abcdabhwgaha的无序度为4,详情:DisordeDegree [index=6, str=abcdabhwgaha, disordeDegree=4]
字符串abcdabgwgaha的无序度为4,详情:DisordeDegree [index=7, str=abcdabgwgaha, disordeDegree=4]
字符串abcdabghgaha的无序度为4,详情:DisordeDegree [index=8, str=abcdabghgaha, disordeDegree=4]
字符串abcdabghwaha的无序度为3,详情:DisordeDegree [index=9, str=abcdabghwaha, disordeDegree=3]
字符串abcdabghwgha的无序度为3,详情:DisordeDegree [index=10, str=abcdabghwgha, disordeDegree=3]
字符串abcdabghwgaa的无序度为4,详情:DisordeDegree [index=11, str=abcdabghwgaa, disordeDegree=4]
字符串abcdabghwgah的无序度为3,详情:DisordeDegree [index=12, str=abcdabghwgah, disordeDegree=3]
移除一个字符串后得到的字符串列表,返回最小无序度的字符串为:[DisordeDegree [index=9, str=abcdabghwaha, disordeDegree=3], DisordeDegree [index=10, str=abcdabghwgha, disordeDegree=3], DisordeDegree [index=12, str=abcdabghwgah, disordeDegree=3]]
移除字符串abcdabghwgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串:[DisordeDegree [index=9, str=abcdabghwaha, disordeDegree=3], DisordeDegree [index=10, str=abcdabghwgha, disordeDegree=3], DisordeDegree [index=12, str=abcdabghwgah, disordeDegree=3]]
移除字符串abcdabghwgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串,移除字符串:DisordeDegree [index=9, str=abcdabghwaha, disordeDegree=3]
移除字符串abcdabghwaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串,移除字符串结果:abcdabghwaha

……

开始递归移除字符串wah,无序度为1,游戏进度,第13步
输入字符串:wah,移除一个字符,得到的字符串列表:[ah, wh, wa]
字符串ah的无序度为0,详情:DisordeDegree [index=0, str=ah, disordeDegree=0]
字符串wh的无序度为1,详情:DisordeDegree [index=1, str=wh, disordeDegree=1]
字符串wa的无序度为1,详情:DisordeDegree [index=2, str=wa, disordeDegree=1]
移除一个字符串后得到的字符串列表,返回最小无序度的字符串为:[DisordeDegree [index=0, str=ah, disordeDegree=0]]
移除字符串wah的一个字符后,返回最小无序度的字符串为严格递增的字符串:0
输入字符串:abcdcabghwhgaha,游戏结果为1
  • 打赏
  • 举报
回复
引用 17 楼 zhamge 的回复:
别人出题的是有答案的吧,不然测试用例怎么判断对错啊。
只是知道对错还不容易? 用几个模拟场景试试呗, 比如四色图的"证明"
u011277123 2013-12-09
  • 打赏
  • 举报
回复
为什么16楼的答案不对呢?
softee 2013-12-08
  • 打赏
  • 举报
回复
给大家提供解体思路: http://blog.csdn.net/softee/article/details/17198647
Hony杨 2013-12-06
  • 打赏
  • 举报
回复
已经过了,不过不是第一次过的:http://blog.csdn.net/huiyuyang_fish/article/details/17169025
zhamge 2013-12-06
  • 打赏
  • 举报
回复
别人出题的是有答案的吧,不然测试用例怎么判断对错啊。
没有名字啊啊 2013-12-02
  • 打赏
  • 举报
回复
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;


public class Test {
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		System.out.println("请输入字母");
		int y = who(s.next());
		System.out.println(y);
	}
	 public static  int who(String word){
		 StringBuilder s1 = new StringBuilder(word);
		 StringBuilder s2;
		 int x = 0;
		 while (true) {
			 x++;
				int i =getch(s1.toString());
					s1.deleteCharAt(i);
					s2=new StringBuilder(s1.toString());
					char[] ch = s2.toString().toCharArray();
					Arrays.sort(ch);
					boolean b = Arrays.equals(ch, s1.toString().toCharArray());
					if (b) {
						if (x%2!=0) {
							return 1;
						}else{
							return 0;
						}
					}else{
						continue;
					}
		}
	 }
	 public static int getch(String s){
		 char[] ch = s.toCharArray();
		 int num = 0;
		 int num1 = 0;
		 int num2 = 0;
		 Character c=null ;
		 boolean b = false;
		 Random r = new Random();
		 for (int i = 0; i < ch.length-1; i++) {
			 num2 ++;
			 for (int j = i+1; j < ch.length; j++) {
				if (ch[i]==ch[j]) {
					b = true;
					num+=1;
				}
			}
			 if (num!=0) {
				if (num1!=0) {
					if (num1<num) {
						num1 =num;
						c= ch[i];
					}
				}else{
					num1 = num;
					c = ch[i];
				}
			}
		}
		 System.out.println(c);
		 if (!b&&num2+1 ==ch.length) {
			 System.out.println("没有重复 的");
			return r.nextInt(ch.length);
		}else{
			return s.indexOf(c.toString());
		}
	 }
}
我用的比较简单,如果真的够聪明的话,如果剩下ZAF 那么甲是不是就会选择把Z拿掉?这样就赢了?
androidwifi 2013-12-01
  • 打赏
  • 举报
回复
这道题应该是某个项目中用到的核心算法。。。几千块就买个,文思太会赚了,,用个人来做的话至少一个星期,就不值这个价了。。。
Fly_Miss 2013-11-30
  • 打赏
  • 举报
回复
yaofeng168 2013-11-28
  • 打赏
  • 举报
回复
输入字符串:abcdcabghwhgaha,字符串长度:15,无序度为6 开始递归移除字符串abcdcabghwhgaha,无序度为6,游戏进度,第1步 输入字符串:abcdcabghwhgaha,移除一个字符,得到的字符串列表:[bcdcabghwhgaha, acdcabghwhgaha, abdcabghwhgaha, abccabghwhgaha, abcdabghwhgaha, abcdcbghwhgaha, abcdcaghwhgaha, abcdcabhwhgaha, abcdcabgwhgaha, abcdcabghhgaha, abcdcabghwgaha, abcdcabghwhaha, abcdcabghwhgha, abcdcabghwhgaa, abcdcabghwhgah] 字符串bcdcabghwhgaha的无序度为6,详情:DisordeDegree [index=0, str=bcdcabghwhgaha, disordeDegree=6] 字符串acdcabghwhgaha的无序度为6,详情:DisordeDegree [index=1, str=acdcabghwhgaha, disordeDegree=6] 字符串abdcabghwhgaha的无序度为6,详情:DisordeDegree [index=2, str=abdcabghwhgaha, disordeDegree=6] 字符串abccabghwhgaha的无序度为6,详情:DisordeDegree [index=3, str=abccabghwhgaha, disordeDegree=6] 字符串abcdabghwhgaha的无序度为5,详情:DisordeDegree [index=4, str=abcdabghwhgaha, disordeDegree=5] 字符串abcdcbghwhgaha的无序度为6,详情:DisordeDegree [index=5, str=abcdcbghwhgaha, disordeDegree=6] 字符串abcdcaghwhgaha的无序度为6,详情:DisordeDegree [index=6, str=abcdcaghwhgaha, disordeDegree=6] 字符串abcdcabhwhgaha的无序度为6,详情:DisordeDegree [index=7, str=abcdcabhwhgaha, disordeDegree=6] 字符串abcdcabgwhgaha的无序度为6,详情:DisordeDegree [index=8, str=abcdcabgwhgaha, disordeDegree=6] 字符串abcdcabghhgaha的无序度为6,详情:DisordeDegree [index=9, str=abcdcabghhgaha, disordeDegree=6] 字符串abcdcabghwgaha的无序度为5,详情:DisordeDegree [index=10, str=abcdcabghwgaha, disordeDegree=5] 字符串abcdcabghwhaha的无序度为5,详情:DisordeDegree [index=11, str=abcdcabghwhaha, disordeDegree=5] 字符串abcdcabghwhgha的无序度为5,详情:DisordeDegree [index=12, str=abcdcabghwhgha, disordeDegree=5] 字符串abcdcabghwhgaa的无序度为6,详情:DisordeDegree [index=13, str=abcdcabghwhgaa, disordeDegree=6] 字符串abcdcabghwhgah的无序度为5,详情:DisordeDegree [index=14, str=abcdcabghwhgah, disordeDegree=5] 移除一个字符串后得到的字符串列表,返回最小无序度的字符串为:[DisordeDegree [index=4, str=abcdabghwhgaha, disordeDegree=5], DisordeDegree [index=10, str=abcdcabghwgaha, disordeDegree=5], DisordeDegree [index=11, str=abcdcabghwhaha, disordeDegree=5], DisordeDegree [index=12, str=abcdcabghwhgha, disordeDegree=5], DisordeDegree [index=14, str=abcdcabghwhgah, disordeDegree=5]] 移除字符串abcdcabghwhgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串:[DisordeDegree [index=4, str=abcdabghwhgaha, disordeDegree=5], DisordeDegree [index=10, str=abcdcabghwgaha, disordeDegree=5], DisordeDegree [index=11, str=abcdcabghwhaha, disordeDegree=5], DisordeDegree [index=12, str=abcdcabghwhgha, disordeDegree=5], DisordeDegree [index=14, str=abcdcabghwhgah, disordeDegree=5]] 移除字符串abcdcabghwhgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串,移除字符串:DisordeDegree [index=4, str=abcdabghwhgaha, disordeDegree=5] 移除字符串abcdabghwhgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串,移除字符串结果:abcdabghwhgaha 开始递归移除字符串abcdabghwhgaha,无序度为5,游戏进度,第2步 输入字符串:abcdabghwhgaha,移除一个字符,得到的字符串列表:[bcdabghwhgaha, acdabghwhgaha, abdabghwhgaha, abcabghwhgaha, abcdbghwhgaha, abcdaghwhgaha, abcdabhwhgaha, abcdabgwhgaha, abcdabghhgaha, abcdabghwgaha, abcdabghwhaha, abcdabghwhgha, abcdabghwhgaa, abcdabghwhgah] 字符串bcdabghwhgaha的无序度为5,详情:DisordeDegree [index=0, str=bcdabghwhgaha, disordeDegree=5] 字符串acdabghwhgaha的无序度为5,详情:DisordeDegree [index=1, str=acdabghwhgaha, disordeDegree=5] 字符串abdabghwhgaha的无序度为5,详情:DisordeDegree [index=2, str=abdabghwhgaha, disordeDegree=5] 字符串abcabghwhgaha的无序度为5,详情:DisordeDegree [index=3, str=abcabghwhgaha, disordeDegree=5] 字符串abcdbghwhgaha的无序度为5,详情:DisordeDegree [index=4, str=abcdbghwhgaha, disordeDegree=5] 字符串abcdaghwhgaha的无序度为5,详情:DisordeDegree [index=5, str=abcdaghwhgaha, disordeDegree=5] 字符串abcdabhwhgaha的无序度为5,详情:DisordeDegree [index=6, str=abcdabhwhgaha, disordeDegree=5] 字符串abcdabgwhgaha的无序度为5,详情:DisordeDegree [index=7, str=abcdabgwhgaha, disordeDegree=5] 字符串abcdabghhgaha的无序度为5,详情:DisordeDegree [index=8, str=abcdabghhgaha, disordeDegree=5] 字符串abcdabghwgaha的无序度为4,详情:DisordeDegree [index=9, str=abcdabghwgaha, disordeDegree=4] 字符串abcdabghwhaha的无序度为4,详情:DisordeDegree [index=10, str=abcdabghwhaha, disordeDegree=4] 字符串abcdabghwhgha的无序度为4,详情:DisordeDegree [index=11, str=abcdabghwhgha, disordeDegree=4] 字符串abcdabghwhgaa的无序度为5,详情:DisordeDegree [index=12, str=abcdabghwhgaa, disordeDegree=5] 字符串abcdabghwhgah的无序度为4,详情:DisordeDegree [index=13, str=abcdabghwhgah, disordeDegree=4] 移除一个字符串后得到的字符串列表,返回最小无序度的字符串为:[DisordeDegree [index=9, str=abcdabghwgaha, disordeDegree=4], DisordeDegree [index=10, str=abcdabghwhaha, disordeDegree=4], DisordeDegree [index=11, str=abcdabghwhgha, disordeDegree=4], DisordeDegree [index=13, str=abcdabghwhgah, disordeDegree=4]] 移除字符串abcdabghwhgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串:[DisordeDegree [index=9, str=abcdabghwgaha, disordeDegree=4], DisordeDegree [index=10, str=abcdabghwhaha, disordeDegree=4], DisordeDegree [index=11, str=abcdabghwhgha, disordeDegree=4], DisordeDegree [index=13, str=abcdabghwhgah, disordeDegree=4]] 移除字符串abcdabghwhgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串,移除字符串:DisordeDegree [index=9, str=abcdabghwgaha, disordeDegree=4] 移除字符串abcdabghwgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串,移除字符串结果:abcdabghwgaha 开始递归移除字符串abcdabghwgaha,无序度为4,游戏进度,第3步 输入字符串:abcdabghwgaha,移除一个字符,得到的字符串列表:[bcdabghwgaha, acdabghwgaha, abdabghwgaha, abcabghwgaha, abcdbghwgaha, abcdaghwgaha, abcdabhwgaha, abcdabgwgaha, abcdabghgaha, abcdabghwaha, abcdabghwgha, abcdabghwgaa, abcdabghwgah] 字符串bcdabghwgaha的无序度为4,详情:DisordeDegree [index=0, str=bcdabghwgaha, disordeDegree=4] 字符串acdabghwgaha的无序度为4,详情:DisordeDegree [index=1, str=acdabghwgaha, disordeDegree=4] 字符串abdabghwgaha的无序度为4,详情:DisordeDegree [index=2, str=abdabghwgaha, disordeDegree=4] 字符串abcabghwgaha的无序度为4,详情:DisordeDegree [index=3, str=abcabghwgaha, disordeDegree=4] 字符串abcdbghwgaha的无序度为4,详情:DisordeDegree [index=4, str=abcdbghwgaha, disordeDegree=4] 字符串abcdaghwgaha的无序度为4,详情:DisordeDegree [index=5, str=abcdaghwgaha, disordeDegree=4] 字符串abcdabhwgaha的无序度为4,详情:DisordeDegree [index=6, str=abcdabhwgaha, disordeDegree=4] 字符串abcdabgwgaha的无序度为4,详情:DisordeDegree [index=7, str=abcdabgwgaha, disordeDegree=4] 字符串abcdabghgaha的无序度为4,详情:DisordeDegree [index=8, str=abcdabghgaha, disordeDegree=4] 字符串abcdabghwaha的无序度为3,详情:DisordeDegree [index=9, str=abcdabghwaha, disordeDegree=3] 字符串abcdabghwgha的无序度为3,详情:DisordeDegree [index=10, str=abcdabghwgha, disordeDegree=3] 字符串abcdabghwgaa的无序度为4,详情:DisordeDegree [index=11, str=abcdabghwgaa, disordeDegree=4] 字符串abcdabghwgah的无序度为3,详情:DisordeDegree [index=12, str=abcdabghwgah, disordeDegree=3] 移除一个字符串后得到的字符串列表,返回最小无序度的字符串为:[DisordeDegree [index=9, str=abcdabghwaha, disordeDegree=3], DisordeDegree [index=10, str=abcdabghwgha, disordeDegree=3], DisordeDegree [index=12, str=abcdabghwgah, disordeDegree=3]] 移除字符串abcdabghwgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串:[DisordeDegree [index=9, str=abcdabghwaha, disordeDegree=3], DisordeDegree [index=10, str=abcdabghwgha, disordeDegree=3], DisordeDegree [index=12, str=abcdabghwgah, disordeDegree=3]] 移除字符串abcdabghwgaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串,移除字符串:DisordeDegree [index=9, str=abcdabghwaha, disordeDegree=3] 移除字符串abcdabghwaha的一个字符后,返回最小无序度的字符串不是严格递增的字符串,移除字符串结果:abcdabghwaha …… 开始递归移除字符串wah,无序度为1,游戏进度,第13步 输入字符串:wah,移除一个字符,得到的字符串列表:[ah, wh, wa] 字符串ah的无序度为0,详情:DisordeDegree [index=0, str=ah, disordeDegree=0] 字符串wh的无序度为1,详情:DisordeDegree [index=1, str=wh, disordeDegree=1] 字符串wa的无序度为1,详情:DisordeDegree [index=2, str=wa, disordeDegree=1] 移除一个字符串后得到的字符串列表,返回最小无序度的字符串为:[DisordeDegree [index=0, str=ah, disordeDegree=0]] 移除字符串wah的一个字符后,返回最小无序度的字符串为严格递增的字符串:0 输入字符串:abcdcabghwhgaha,游戏结果为1
  • 打赏
  • 举报
回复
引用 8 楼 Sum_ck 的回复:
[quote=引用 7 楼 huang1900zz 的回复:] [quote=引用 5 楼 Sum_ck 的回复:] 贴一下我代码,大神帮忙看看哪里错了。。。 用的思想是线代的逆序对。

public class Test {
	public static void main(String[] args) {
		String string="vgwgpkxxkqmnx";
		System.out.println(who(string));
	}
	public static int who(String word){
		String word2=word;
		int maxIndex;//逆序最大数
		int count=0;//count为奇数甲操作,count为偶数乙操作
		while(maxCount(word2)>0){
			//System.out.println(word2);
			maxIndex=maxCount(word2);
			word2=word2.substring(0,maxIndex)+word2.substring(maxIndex+1,word2.length());
			count++;
		}
		return count%2;
	}
	private static int maxCount(String in){
		int[] a=new int[in.length()];
		int max=0;
		int maxIndex=0;
		char[] chs=in.toCharArray(); 
		for(int i=0;i<in.length()-1;i++)
			for(int j=i+1;j<in.length();j++){
				if(chs[i]>=chs[j]){
					a[i]++;
					a[j]++;
				}
			}
		for(int i=0;i<a.length;i++){
			//System.out.print(a[i]+"  ");
			if(a[i]>max){
				max=a[i];
				maxIndex=i;
			}
		}
		//System.out.println();
		return maxIndex;
	}
}
你忘记题目说过甲乙都是有策略的 优先考虑消除较多无序对的节点可以加快算法,但是甲乙是通过选择无序对较少的字母 或者有序字母 来取胜的 “甲乙都够聪明”水就深了[/quote] 那我只能呵呵了。。。[/quote] 这种东西都是内定的,除非你的思路很牛逼,然后然后还要进他们公司吧
Rlay_2 2013-11-27
  • 打赏
  • 举报
回复
我看了一眼,不是研究算法的,没什么思路
ghw554557313 2013-11-27
  • 打赏
  • 举报
回复
chaojikugua 2013-11-27
  • 打赏
  • 举报
回复
没有人做出来吗?
我若为王lg 2013-11-27
  • 打赏
  • 举报
回复
1,先计算所有字母与其他字母的逆序个数 2,甲删除逆序个数最多的 3,乙删除逆序个数最少的 4,若剩余所有字母逆序数都为0,且剩余数大于1,则甲胜 5,若剩余字母小于等于1,则乙胜 这个思路可以么
老萨 2013-11-27
  • 打赏
  • 举报
回复
引用 7 楼 huang1900zz 的回复:
[quote=引用 5 楼 Sum_ck 的回复:]
贴一下我代码,大神帮忙看看哪里错了。。。
用的思想是线代的逆序对。


public class Test {
public static void main(String[] args) {
String string="vgwgpkxxkqmnx";
System.out.println(who(string));
}
public static int who(String word){
String word2=word;
int maxIndex;//逆序最大数
int count=0;//count为奇数甲操作,count为偶数乙操作
while(maxCount(word2)>0){
//System.out.println(word2);
maxIndex=maxCount(word2);
word2=word2.substring(0,maxIndex)+word2.substring(maxIndex+1,word2.length());
count++;
}
return count%2;
}
private static int maxCount(String in){
int[] a=new int[in.length()];
int max=0;
int maxIndex=0;
char[] chs=in.toCharArray();
for(int i=0;i<in.length()-1;i++)
for(int j=i+1;j<in.length();j++){
if(chs[i]>=chs[j]){
a[i]++;
a[j]++;
}
}
for(int i=0;i<a.length;i++){
//System.out.print(a[i]+" ");
if(a[i]>max){
max=a[i];
maxIndex=i;
}
}
//System.out.println();
return maxIndex;
}
}

你忘记题目说过甲乙都是有策略的 优先考虑消除较多无序对的节点可以加快算法,但是甲乙是通过选择无序对较少的字母 或者有序字母 来取胜的 “甲乙都够聪明”水就深了[/quote]
那我只能呵呵了。。。
huang1900zz 2013-11-27
  • 打赏
  • 举报
回复
引用 5 楼 Sum_ck 的回复:
贴一下我代码,大神帮忙看看哪里错了。。。 用的思想是线代的逆序对。

public class Test {
	public static void main(String[] args) {
		String string="vgwgpkxxkqmnx";
		System.out.println(who(string));
	}
	public static int who(String word){
		String word2=word;
		int maxIndex;//逆序最大数
		int count=0;//count为奇数甲操作,count为偶数乙操作
		while(maxCount(word2)>0){
			//System.out.println(word2);
			maxIndex=maxCount(word2);
			word2=word2.substring(0,maxIndex)+word2.substring(maxIndex+1,word2.length());
			count++;
		}
		return count%2;
	}
	private static int maxCount(String in){
		int[] a=new int[in.length()];
		int max=0;
		int maxIndex=0;
		char[] chs=in.toCharArray(); 
		for(int i=0;i<in.length()-1;i++)
			for(int j=i+1;j<in.length();j++){
				if(chs[i]>=chs[j]){
					a[i]++;
					a[j]++;
				}
			}
		for(int i=0;i<a.length;i++){
			//System.out.print(a[i]+"  ");
			if(a[i]>max){
				max=a[i];
				maxIndex=i;
			}
		}
		//System.out.println();
		return maxIndex;
	}
}
你忘记题目说过甲乙都是有策略的 优先考虑消除较多无序对的节点可以加快算法,但是甲乙是通过选择无序对较少的字母 或者有序字母 来取胜的 “甲乙都够聪明”水就深了
ghw554557313 2013-11-27
  • 打赏
  • 举报
回复
放下了 没思路
老萨 2013-11-27
  • 打赏
  • 举报
回复
贴一下我代码,大神帮忙看看哪里错了。。。 用的思想是线代的逆序对。

public class Test {
	public static void main(String[] args) {
		String string="vgwgpkxxkqmnx";
		System.out.println(who(string));
	}
	public static int who(String word){
		String word2=word;
		int maxIndex;//逆序最大数
		int count=0;//count为奇数甲操作,count为偶数乙操作
		while(maxCount(word2)>0){
			//System.out.println(word2);
			maxIndex=maxCount(word2);
			word2=word2.substring(0,maxIndex)+word2.substring(maxIndex+1,word2.length());
			count++;
		}
		return count%2;
	}
	private static int maxCount(String in){
		int[] a=new int[in.length()];
		int max=0;
		int maxIndex=0;
		char[] chs=in.toCharArray(); 
		for(int i=0;i<in.length()-1;i++)
			for(int j=i+1;j<in.length();j++){
				if(chs[i]>=chs[j]){
					a[i]++;
					a[j]++;
				}
			}
		for(int i=0;i<a.length;i++){
			//System.out.print(a[i]+"  ");
			if(a[i]>max){
				max=a[i];
				maxIndex=i;
			}
		}
		//System.out.println();
		return maxIndex;
	}
}
南猿北蛰 2013-11-27
  • 打赏
  • 举报
回复
顶一下,看了一下,没什么思路。
加载更多回复(1)

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧