| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1967 人关注过本帖
标题:老师出了一道题,只能写到这样,总是有错误,求大神指导
取消只看楼主 加入收藏
csy1120
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-9-17
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
老师出了一道题,只能写到这样,总是有错误,求大神指导
A、B、C、D、E、F、G、H、I、J 共10名学生有可能参加本次计算机竞赛,也可能不参加。因为某种原因,他们是否参赛受到下列条件的约束:
   1. 如果A参加,B也参加;
   2. 如果C不参加,D也不参加;
   3. A和C中只能有一个人参加;
   4. B和D中有且仅有一个人参加;
   5. D、E、F、G、H 中至少有2人参加;
   6. C和G或者都参加,或者都不参加;
   7. C、E、G、I中至多只能2人参加   
   8. 如果E参加,那么F和G也都参加。
   9. 如果F参加,G、H就不能参加
   10. 如果I、J都不参加,H必须参加
请编程根据这些条件判断这10名同学中参赛者名单。如果有多种可能,则输出所有的可能情况。



public class Test{

    public static void main (String[] args){
            int[] constvalue = {1,2,4,8,16,32,64,128,256,512};
            for(int i=0;i<1024;i++){
                if(((i&constvalue['a'-'a'])==constvalue['a'-'a'])
                    &&((i&constvalue['b'-'a'])==0)){
                    continue;}
                if(!((i&constvalue['c'-'a'])==constvalue['c'-'a'])
                    &&((i&constvalue['d'-'a'])==constvalue['d'-'a'])){
                    continue;}
                if(((i&constvalue['a'-'a'])==constvalue['a'-'a'])
                    &&((i&constvalue['c'-'a'])==constvalue['c'-'a'])){
                    continue;}
                if((((i&constvalue['b'-'a'])==constvalue['b'-'a'])&&((i&constvalue['d'-'a'])==constvalue['d'-'a']))
                    ||(!(i&constvalue['b'-'a']==constvalue['b'-'a'])&&!((i&constvalue['d'-'a'])==constvalue['d'-'a']))){
                    continue;}
                if((((i&constvalue['d'-'a'])==constvalue['d'-'a'])+((i&constvalue['e'-'a'])==constvalue['e'-'a'])+
                    ((i&constvalue['f'-'a'])==constvalue['f'-'a'])+((i&constvalue['g'-'a'])==constvalue['g'-'a'])+
                    ((i&constvalue['h'-'a'])==constvalue['h'-'a']))<2){
                    continue;}
                if((!((i&constvalue['c'-'a'])==constvalue['c'-'a'])&&((i&constvalue['g'-'a'])==constvalue['g'-'a']))
                    ||(((i&constvalue['c'-'a'])==constvalue['c'-'a'])&&(!((i&constvalue['g'-'a'])==constvalue['g'-'a'])))){
                    continue;}
                if((((i&constvalue['c'-'a'])==constvalue['c'-'a'])+((i&constvalue['e'-'a'])==constvalue['e'-'a'])+
                    ((i&constvalue['g'-'a'])==constvalue['g'-'a'])+((i&constvalue['i'-'a'])==constvalue['i'-'a']))>2){
                    continue;}
                if((((i&constvalue['e'-'a'])==constvalue['e'-'a'])&&(!((i&constvalue['f'-'a'])==constvalue['f'-'a'])))
                    ||(((i&constvalue['e'-'a'])==constvalue['e'-'a'])&&(!((i&constvalue['g'-'a'])==constvalue['g'-'a'])))){
                    continue;}
                if((((i&constvalue['f'-'a'])==constvalue['f'-'a'])&&((i&constvalue['g'-'a'])==constvalue['g'-'a']))
                    ||(((i&constvalue['f'-'a'])==constvalue['f'-'a'])&&((i&constvalue['h'-'a'])==constvalue['h'-'a']))){
                    continue;}
                if(((!((i&constvalue['i'-'a'])==constvalue['i'-'a']))&&(!((i&constvalue['j'-'a'])==constvalue['j'-'a']))
                    &&(!((i&constvalue['h'-'a'])==constvalue['h'-'a'])))){
                    continue;}
                if((i&constvalue['a'-'a'])==constvalue['a'-'a']){
                    System.out.print("A");}
                if((i&constvalue['b'-'a'])==constvalue['b'-'a']){
                    System.out.print("B");}
                if((i&constvalue['c'-'a'])==constvalue['c'-'a']){
                    System.out.print("C");}
                if((i&constvalue['d'-'a'])==constvalue['d'-'a']){
                    System.out.print("D");}
                if((i&constvalue['e'-'a'])==constvalue['e'-'a']){
                    System.out.print("E");}
                if((i&constvalue['f'-'a'])==constvalue['f'-'a']){
                    System.out.print("F");}
                if((i&constvalue['g'-'a'])==constvalue['g'-'a']){
                    System.out.print("G");
                if((i&constvalue['h'-'a'])==constvalue['h'-'a']){
                    System.out.print("H");}
                if((i&constvalue['i'-'a'])==constvalue['i'-'a']){
                    System.out.print("I");}
                if((i&constvalue['j'-'a'])==constvalue['j'-'a']){
                    System.out.print("J");}
                System.out.println();
               
                }
                    
        }
    }
}
搜索更多相关主题的帖子: 计算机 
2016-09-17 16:57
csy1120
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-9-17
收藏
得分:0 
回复 3楼 hhwz
分别代表A,B,C........等   
2016-09-20 22:11
快速回复:老师出了一道题,只能写到这样,总是有错误,求大神指导
数据加载中...
 
   



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

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