C. Bitwise Operation Wizard

2024-03-02 16:20
文章标签 operation wizard bitwise

本文主要是介绍C. Bitwise Operation Wizard,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 解题思路

  • a,b,c,d可以相同
  • 先通过Px|Px,找出最大值mx
  • 再通过每个数与mx取或,记录得值最大时的每个数
  • 其中的最小值与mxxor最大

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();staticclass 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();}}
}

 

这篇关于C. Bitwise Operation Wizard的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/766724

相关文章

[LeetCode] 583. Delete Operation for Two Strings

题:https://leetcode.com/problems/delete-operation-for-two-strings/description/ 题目 Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in

macos 系统文件操作时提示 Operation not permitted 异常解决方法 , 通过恢复模式 开启 /关闭 SIP方法

在macos系统中操作系统文件时提示 Operation not permitted  这个异常, 原因是因为在macos 10.11以上版本中默认启用了 SIP( System Integrity Protection )机制对系统文件进行保护,  要解决这个问题我们需要关机, 然后进入mac的恢复模式 :  在按电源键开机的同时, 一直按住 command + r 键 直到出现恢复模式界面后松

电脑开机出现no operation system found错误原因分析及解决方法

最近有网友问我电脑一启动提示:no operation system found,这个提示意思是未找到操作系统。并且出现bios能认别硬盘,快捷启动时找不到硬盘,出现该提示的原因有很多,下面我们来详细分析一下开机出现no operation system found解决方法全集。 电脑开机出现no operation system found错误原因分析及注意事项: 电脑开机时出

【LINUX】“dmesg: read kernel buffer failed: Operation not permitted“ 错误

出现 “dmesg: read kernel buffer failed: Operation not permitted” 错误通常是因为当前用户没有权限读取内核日志缓冲区 这可以通过修改内核参数 kernel.dmesg_restrict 来解决。 你可以尝试以下命令来允许非特权用户读取内核日志: sudo sysctl -w kernel.dmesg_restrict=0 这个命令

位操作(Bitwise Operation)

位操作(Bitwise Operation)是一种直接对整数的二进制位进行操作的计算方法。在计算机中,数据通常以二进制形式存储,位操作允许我们直接操作这些二进制位。位操作通常比常规的算术运算更高效,因为它们直接作用于二进制位而不涉及更复杂的计算。 常见的位操作符 1.按位与(&): 对应位都为1时,结果为1,否则为0。 例如:1010 & 1100 = 1000 2.按位或(|): 只要对应

rl: (7) Failed to connect to get.rvm.io port 443: Operation timed out

问题:curl -L https://get.rvm.io | bash -s stable 命令失败 报错内容: rl: (7) Failed to connect to get.rvm.io port 443: Operation timed out 或 curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection t

mac IDEA java 没有javap 安装 The operation couldn’t be completed. Unable to locate a Java Runtime.

一、直接从官网下载需要的JDK版本 https://www.jianshu.com/p/fe6b68295479   二、javap Error: class not found 1.用javac 类名 的命令生成class文件   2. 用javap -c 类名 命令进行拆解代码     https://blog.csdn.net/en_joker/article

qt6 socket 不使用代理 socket error: The proxy type is invalid for this operation

qt 5.8之后,socket默认使用代理 参考 https://www.cnblogs.com/cppskill/p/11730452.html#:~:text=%E5%9C%A8%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E9%87%8C%E5%AE%9A%E4%B9%89,Proxy%29%3B%E3%80%82 #include <QNetworkProx

The user operation is waiting for building workspace to complete”

今天在运行android程序时,显示“the user operation is waiting for "building workspace" tocomplete”,查找解决办法如下:   1.选择菜单栏的“Project”,然后把菜单栏中“BuildAutomatically”前面的对钩去掉。 2.当你修改或添加代码后,选择菜单栏的“Project”,然后选择菜单栏中“BuildA