当前位置: 首页 > news >正文

E - Bad Juice

解题思路

  • 由于最后返回一个01字符串表示所选人的状态
  • 要求人数最少,即字符串长度最少
  • 而要用最少的字符,找出Bad\ juice
  • 则返回的字符为二进制下Bad\ juice的编号
  • 这样利用了所有的01字符
  • i号人表示二进制下i位的情况
  • 注意对于2的次方项n=2^k,只需要有k-1位,n可以用k-1位均为0表示
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;static class Node{int x;int y;public Node(int u,int v) {x=u;y=v;}}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 n=input.nextInt();//返回的二进制字符串即为变质的编号int t=0;while((1<<t)<n)t++;System.out.println(t);int[] c=new int[n+1];for(int i=0;i<t;++i) {for(int j=1;j<=n;++j) {if(((j>>i)&1)==1)c[i]++;}}for(int i=0;i<t;++i) {System.out.print(c[i]);for(int j=1;j<=n;++j) {if(((j>>i)&1)==1)System.out.print(" "+j);}System.out.println();}String string=input.next();char[] s=string.toCharArray();int ans=0;for(int i=0;i<t;++i) {if(s[i]=='1')ans|=(1<<i);}if(ans==0)ans=n;System.out.println(ans);System.out.flush();
// 	    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();}}
}

 

http://www.lryc.cn/news/309211.html

相关文章:

  • 用HTML5的<canvas>元素实现刮刮乐游戏
  • TypeScript + react 中 TypeScript 的加入后 , 有哪些优化项目
  • Redis学习路径(构建体系)
  • 【README 小技巧】 展示gitee中开源项目start
  • tcping实用小工具
  • 【Web】Java反序列化之CC2——commons-collections4的新链之一
  • golang使用gorm操作mysql1
  • Flutter异常上报及性能监控实现
  • 基于springboot+vue的工厂车间管理系统
  • Java基础 - Stream 流:Stream API的终端操作
  • 高级语言期末2009级A卷(计算机学院)
  • docker-compose搭建php开发环境
  • 翻译论文:Beating Floating Point at its Own Game: Posit Arithmetic(一)
  • 【数据结构-图论】并查集
  • 云计算时代的运维: 职业发展方向与岗位选择
  • java锁底层概述
  • win10如何添加指纹登陆
  • 足底筋膜炎的症状及治疗
  • udp丢包问题研究
  • 在idea中用模板骨架初始创建maven管理的web项目时没有src有关的目录的解决方案
  • WPF 【十月的寒流】学习笔记(2):MVVM中是怎么实现通知的
  • 数据结构:广义表
  • 你好,C++(18) 到底要不要买这个西瓜?4.1.6 操作符之间的优先顺序
  • C语言 for 循环语句的基本格式是什么?
  • 项目-SERVER模块-日志宏
  • TCP为什么要三次握手?
  • 网络防御第6次作业
  • Jmeter分布式部署
  • Odoo迈入开源第一低代码开发平台的重要里程碑
  • WinForm、Wpf自动升级 AutoUpdater.NET