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();
	    }
	}
}
相关推荐
郝学胜-神的一滴10 小时前
计算机图形学中的光照模型:从基础到现代技术
开发语言·c++·程序人生·图形渲染
lly20240610 小时前
PostgreSQL 表达式
开发语言
LXMXHJ10 小时前
php开发
开发语言·php
望获linux11 小时前
【实时Linux实战系列】Linux 内核的实时组调度(Real-Time Group Scheduling)
java·linux·服务器·前端·数据库·人工智能·深度学习
Never_Satisfied11 小时前
在 JavaScript 中,删除数组中内容为xxx的元素
java·前端·javascript
MC丶科11 小时前
【SpringBoot常见报错与解决方案】端口被占用?Spring Boot 修改端口号的 3 种方法,第 3 种 90% 的人不知道!
java·linux·spring boot
怪兽201411 小时前
Redis常见性能问题和解决方案
java·数据库·redis·面试
zz-zjx11 小时前
JVM 内存结构与 GC 机制详解( 实战优化版)
java·jvm·tomcat
mjhcsp11 小时前
MATLAB 疑难问题诊疗:从常见报错到深度优化的全流程指南
开发语言·matlab
Lynnxiaowen11 小时前
今天我们开始学习python语句和模块
linux·运维·开发语言·python·学习