Codeforces 494 div3 (ABCD)

从暑假开始做cf,感觉cf的题目很好,div3难度正好也挺适合我这种垃圾的。 题目链接
A:要找分割的最小次数,其实就是求同一个元素出现的最大次数。用hashmap即可。

package codeforces494;import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;public class codeA {public static void main(String[] args) {Scanner sc=new Scanner(System.in);int n=sc.nextInt();Map <Integer,Integer>map=new HashMap();int max=1;for(int i=0;i<n;i++){int j=sc.nextInt();if(map.containsKey(j)) {map.put(j, map.get(j)+1);if(map.get(j)>max) {max=map.get(j);}}else{map.put(j, 1);}}System.out.println(max);}
}

B:要求写出一种满足要求数量的01不同的策略。贪心,分奇偶讨论。一个为整,一个插入就行。

package codeforces494;import java.util.Scanner;public class codeB {public static void main(String[] args) {Scanner sc=new Scanner(System.in);int a=sc.nextInt();//a个0int b=sc.nextInt();int x=sc.nextInt();//x个StringBuffer bu=new StringBuffer("");for(int i=0;i<a;i++){bu.append("0");}String s=bu.toString();StringBuffer bu2=new StringBuffer("");for(int i=0;i<b;i++){bu2.append("1");}String s2=bu2.toString();if(s.length()<s2.length()){String team=s;s=s2;s2=team;a=b;}if(x%2==0)//偶数{int team=x;if(x>2){while(team>2){s=s.substring(0,a-1-(x-team)/2)+s2.substring(0,1)+s.substring(a-1-(x-team)/2);s2=s2.substring(1);team=team-2;}  s=s.substring(0,a-1-(x-team)/2)+s2+s.substring(a-1-(x-team)/2);}else{s=s.substring(0,1)+s2+s.substring(1);}}else{int team=x;while(team>1){s=s.substring(0,a-1-(x-team)/2)+s2.substring(0,1)+s.substring(a-1-(x-team)/2);s2=s2.substring(1);team=team-2;}s+=s2;}System.out.println(s);}
}

C:求子数列的最大平均值,用dp。

package codeforces494;import java.util.Scanner;public class codeC {public static void main(String[] args) {Scanner sc=new Scanner(System.in);double max=0.0;int n=sc.nextInt();//总个数int k=sc.nextInt();int a[]=new int[(int) n];for(int i=0;i<n;i++){a[i]=sc.nextInt();}int dp[][]=new int [n+1][n];//长度为k,第n个数截至的总和///计算长度为1到长度为k的for(int i=0;i<n;i++){dp[1][i]=a[i];}for(int i=2;i<n+1;i++){for(int j=i-1;j<n;j++){dp[i][j]=dp[i-1][j-1]+a[j];if(i>=k){if((double)dp[i][j]/i>max){max=(double)dp[i][j]/i;}}}}if(k==1){for(int i=0;i<n;i++){if(a[i]>max){max=a[i];}}}
//        for(int i=0;i<n;i++)
//        {//          System.out.print(dp[4][i]+" ");
//        }System.out.println(max);}
}

D:

package codeforces494;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.HashMap;
import java.util.Map;public class codeD {public static void main(String[] args) throws IOException {StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));Map<Long,Integer> map=new HashMap();in.nextToken();int n=(int)in.nval;in.nextToken();int q=(int)in.nval;long value[]=new long[33];//价值输入int number[]=new int[33];value[0]=1;map.put((long) 1, 0);for(int i=1;i<33;i++){value[i]=2*value[i-1];map.put( value[i], i);//System.out.println(value[i]);}     for(int i=0;i<n;i++){in.nextToken();long input=(long)in.nval;int getint=map.get(input);number[getint]++;}int t=31;int count=0;while(q-->0){in.nextToken();int sea=(int)in.nval; count=0;for(int i=t;i>=0;i--){int num=number[i];if(sea<value[i]||num==0) {continue;}else  if(sea>=value[i]&&num>0) {int numb1=(int) (sea/value[i]); numb1=numb1>num?num:numb1;sea-=value[i]*numb1;count+=numb1;                                          }else if(sea==0) {break;}}if(sea==0){System.out.println(count);}else{System.out.println(-1);}           }}
}

Codeforces 494Div3(ABCDJava编写)相关推荐

  1. 解题报告(十八)数论题目泛做(Codeforces 难度:2000 ~ 3000 + )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量的题解和代码,题目难度不一 ...

  2. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  3. Codeforces Round #734 (Div. 3) 题解

    Hello大家好,今天给大家带来的是 Codeforces Round #734 (Div. 3) 的全题目讲解. 本文链接:https://www.lanqiao.cn/questions/2040 ...

  4. CodeForces - 798B Mike and strings

    B. Mike and strings time limit per test2 seconds memory limit per test256 megabytes inputstandard in ...

  5. codeforces beta round 1

    codeforces beta round 1 A Theatre Square in the capital city of Berland has a rectangular shape with ...

  6. [codeforces 1379B] Dubious Cyrpto 公式推导

    Codeforces Round #657 (Div. 2)   参与排名人数8684   错过了难得17:00比赛,可惜 [codeforces 1379B]   Dubious Cyrpto  公 ...

  7. Codeforces与洛谷题目之间跳转油猴插件

    title: Codeforces与洛谷题目之间跳转油猴插件 date: 2023-05-04 15:32:39 categories: 其他 tags: 油猴脚本 Codeforces与洛谷题目之间 ...

  8. Codeforces Round #636 (Div. 3)部分题解

    链接:Codeforces Round #636 (Div. 3) A - Candies 题意:求出一个x满足x+2∗x+4∗x+⋯+2k−1∗x=n且k>1 思路:提出x得x∗(1+2+4+ ...

  9. [codeforces 1364B] Most socially-distanced subsequence 绝对值脱壳的4种形态

    Codeforces Round #649 (Div. 2)  参与排名人数11286 [codeforces 1364B]   Most socially-distanced subsequence ...

最新文章

  1. Spring学习笔记_IOC
  2. 使用 IntraWeb (31) - IntraWeb 的 Xml 操作使用的是 NativeXml
  3. Java黑皮书课后题第2章:2.11(人口统计)重写编程练习题1.11,提示用户输入年数,然后显示这个年数之后的人口值,将1.11中的提示用于这个程序
  4. 逆向推导https的设计过程
  5. 从数据库里读值往TEXT文本里写
  6. .net core 调用c dll_Qt编写DLL给外部程序调用,提供VC/C#/C调用示例(含事件)
  7. VALSE学习(十一):弱监督图像语义分割
  8. java基础学习(7)浅析final,private,public,protected,static等关键以及它们的区别的联系
  9. 《21天学通Java(第6版)》—— 2.11 练习
  10. H5+JS表格全选和删除
  11. Mongo连接可视化工具Robo3T,以及Robo3T使用
  12. html5设置谷歌浏览器兼容性,google浏览器
  13. C# loadlibrary C++dll 句柄为空,dll加载失败
  14. com调用excel后,进程未关闭解决方案
  15. vscode+git浅尝
  16. Flutter学习之倒计时计时器
  17. 个人云服务的搭建(折腾)之旅
  18. macbook pro音质测试软件,【苹果 MacBook Pro 笔记本电脑使用总结】屏幕|性能|音质|续航_摘要频道_什么值得买...
  19. PMP项目管理-PMP答题思路
  20. 2-44钟静雯_day03

热门文章

  1. 2021年北京高校数学建模校际联赛题目 出版社图书印制策略
  2. 从键盘输入一串连续的数字,判断输出是否为电话号码
  3. 135. 分发糖果(贪心算法)
  4. TF-A代码阅读: SP_EL3栈内存-cpu_data内存的介绍(cpu_context介绍)
  5. [HOW TO]-ubuntu20.10搭建openjrok服务指南
  6. [HOW TO]-从github拉取optee代码拉不下来怎么办?
  7. Android keymaster的介绍和总结
  8. [mmu/cache]-ARMV8的cache的维护指令介绍
  9. 命令行编译 WRK ,windbg 调试
  10. (32)第一个驱动程序