C. Bitwise Operation Wizard

解题思路

  • 可以相同
  • 先通过,找出最大值
  • 再通过每个数与取或,记录得值最大时的每个数
  • 其中的最小值与最大
java 复制代码
import java.io.*;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Vector;









public class Main{
	static long md=(long)998244353;
	static long Linf=Long.MAX_VALUE/2;
	static int inf=Integer.MAX_VALUE/2;

	
	
	public static void main(String[] args) throws IOException{
//		AReader input=new AReader();
//	    PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
	    Scanner input=new Scanner(System.in);
	    int T=input.nextInt();
	    while(T>0) {
	    	int n=input.nextInt();
	    	int mx=0;
	    	for(int i=1;i<n;++i) {
	    		System.out.println("? "+i+" "+i+" "+mx+" "+mx);
	    		String y=input.next();
	    		char x=y.charAt(0);
	    		if(x=='<'||x=='=') {
	    			continue;
	    		}else if(x=='>') {
	    			mx=i;
	    		}
	    	}
	    	int b=mx;
	    	int mi=0;
	    	HashSet<Integer> may=new HashSet<Integer>();
	    	for(int i=0;i<n;++i) {
	    		if(i==mx)continue;
	    		System.out.println("? "+i+" "+mx+" "+b+" "+mx);
	    		String y=input.next();
	    		char x=y.charAt(0);
	    		if(x=='<')continue;
	    		else if(x=='>') {
	    			may.clear();
	    			may.add(i);
	    			b=i;
	    			mi=i;
	    		}else {
	    			may.add(i);
	    		}
	    	}
	    	
	    	for(int i:may) {
	    		if(i==mi)continue;
	    		System.out.println("? "+i+" "+i+" "+mi+" "+mi);
	    		String y=input.next();
	    		char x=y.charAt(0);
	    		if(x=='<') {
	    			mi=i;
	    		}
	    	}
	    	System.out.println("! "+mi+" "+mx);
	    	T--;
	    }
 	    System.out.flush();
//	    out.close();
	}
	//System.out.println();
	//out.println();
	static
	class AReader{ 
	    BufferedReader bf;
	    StringTokenizer st;
	    BufferedWriter bw;

	    public AReader(){
	        bf=new BufferedReader(new InputStreamReader(System.in));
	        st=new StringTokenizer("");
	        bw=new BufferedWriter(new OutputStreamWriter(System.out));
	    }
	    public String nextLine() throws IOException{
	        return bf.readLine();
	    }
	    public String next() throws IOException{
	        while(!st.hasMoreTokens()){
	            st=new StringTokenizer(bf.readLine());
	        }
	        return st.nextToken();
	    }
	    public char nextChar() throws IOException{
	        //确定下一个token只有一个字符的时候再用
	        return next().charAt(0);
	    }
	    public int nextInt() throws IOException{
	        return Integer.parseInt(next());
	    }
	    public long nextLong() throws IOException{
	        return Long.parseLong(next());
	    }
	    public double nextDouble() throws IOException{
	        return Double.parseDouble(next());
	    }
	    public float nextFloat() throws IOException{
	        return Float.parseFloat(next());
	    }
	    public byte nextByte() throws IOException{
	        return Byte.parseByte(next());
	    }
	    public short nextShort() throws IOException{
	        return Short.parseShort(next());
	    }
	    public BigInteger nextBigInteger() throws IOException{
	        return new BigInteger(next());
	    }
	    public void println() throws IOException {
	        bw.newLine();
	    }
	    public void println(int[] arr) throws IOException{
	        for (int value : arr) {
	            bw.write(value + " ");
	        }
	        println();
	    }
	    public void println(int l, int r, int[] arr) throws IOException{
	        for (int i = l; i <= r; i ++) {
	            bw.write(arr[i] + " ");
	        }
	        println();
	    }
	    public void println(int a) throws IOException{
	        bw.write(String.valueOf(a));
	        bw.newLine();
	    }
	    public void print(int a) throws IOException{
	        bw.write(String.valueOf(a));
	    }
	    public void println(String a) throws IOException{
	        bw.write(a);
	        bw.newLine();
	    }
	    public void print(String a) throws IOException{
	        bw.write(a);
	    }
	    public void println(long a) throws IOException{
	        bw.write(String.valueOf(a));
	        bw.newLine();
	    }
	    public void print(long a) throws IOException{
	        bw.write(String.valueOf(a));
	    }
	    public void println(double a) throws IOException{
	        bw.write(String.valueOf(a));
	        bw.newLine();
	    }
	    public void print(double a) throws IOException{
	        bw.write(String.valueOf(a));
	    }
	    public void print(char a) throws IOException{
	        bw.write(String.valueOf(a));
	    }
	    public void println(char a) throws IOException{
	        bw.write(String.valueOf(a));
	        bw.newLine();
	    }
	}
}
相关推荐
风逸hhh2 分钟前
python打卡day58@浙大疏锦行
开发语言·python
Q_9709563914 分钟前
java+vue+SpringBoo足球社区管理系统(程序+数据库+报告+部署教程+答辩指导)
java·开发语言·数据库
要开心吖ZSH19 分钟前
微服务架构的演进:迈向云原生
java·微服务·云原生
猫猫的小茶馆27 分钟前
【STM32】预分频因子(Prescaler)和重装载值(Reload Value)
c语言·stm32·单片机·嵌入式硬件·mcu·51单片机
JeffersonZU28 分钟前
Linux/Unix文件IO(文件描述符、原子操作、文件数据结构、open、read、write、fcntl、dup)
linux·c语言·unix·gnu
为了更好的明天而战38 分钟前
Java 中的 ArrayList 和 LinkedList 区别详解(源码级理解)
java·开发语言
JosieBook1 小时前
【Java编程动手学】Java中的数组与集合
java·开发语言·python
qq_589568101 小时前
element-plus按需自动导入的配置 以及icon图标不显示的问题解决
开发语言·javascript·ecmascript
N_NAN_N1 小时前
类图+案例+代码详解:软件设计模式----单例模式
java·单例模式·设计模式
lsx2024061 小时前
SQLite Select 语句详解
开发语言