被虐惨了,实验室里数十位大佬中的一位闲来无事切题(二,然后出了5t,当然我要是状态正常也能出5,主要是又热又有蚊子什么的...

题都挺水的。包括F题。

A:

  略

B:

  找k个最大的数存一下下标然后找段长度就行

  public static void main(String[] args) {
int n = nextInt();
int k = nextInt();
PriorityQueue<Integer> q = new PriorityQueue<>();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = nextInt();
q.add(a[i]);
}
while (q.size()>k){
q.poll();
}
boolean b[] = new boolean[n];
int sum = 0;
int last = 0;
for(int i=n-1;i>=0;i--){
if (q.contains(a[i])){
last=i>last?i:last;
sum+=a[i];
b[i] = true;
q.remove(a[i]);
}
}
out.println(sum);
int temp = -1;
for(int i=0;i<last;i++){
if (b[i]){
out.print(i-temp+" ");
temp = i;
}
}
out.print(n-1-temp);
out.flush();
}

main 方法

C:

  从两个端点向中间遍历

 public static void main(String[] args) {
int n = nextInt();
long d[] = new long[n];
for(int i=0;i<n;i++){
d[i] = nextInt();
}
long sum1 = 0;
long sum3 = 0;
int i=0,j=n-1;
long ans = 0;
while (j>i){
if (sum3==sum1){
ans = sum1>ans?sum1:ans;
sum3+=d[j];
sum1+=d[i];
i++;j--;
if (sum3==sum1)
ans = sum1>ans?sum1:ans;
}else if (sum3<sum1){
sum3+=d[j];
j--;
}else if (sum3>sum1){
sum1+=d[i];
i++;
}
}
if (j==i){
if (sum3<sum1){
sum3+=d[j];
}else if (sum3>sum1){
sum1+=d[i];
}
if (sum3==sum1)
ans = sum1>ans?sum1:ans;
}
out.print(ans);
out.flush();
}

D:

  大水题,四个位置上的元素判断一下情况就行,我直接分的类很莽就不放代码了。

E:

  求出dfs序,顺手存个子树大小,结点下标就完了。

package R498;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Vector; public class Main4 {
static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer tok;
static boolean hasNext()
{
while(tok==null||!tok.hasMoreTokens())
try{
tok=new StringTokenizer(in.readLine());
}
catch(Exception e){
return false;
}
return true;
}
static String next()
{
hasNext();
return tok.nextToken();
}
static long nextLong()
{
return Long.parseLong(next());
}
static int nextInt()
{
return Integer.parseInt(next());
}
static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); static int N = 200005;
static Vector<Integer> g[] = new Vector[N];
static int size[] = new int[N];//存子树大小
static boolean b[] = new boolean[N];//染色
static int ans[] = new int[N];//dfs序
static int index[] = new int[N];//下标
static int pos = 0; public static void main(String[] args) {
int n = nextInt();
int q = nextInt();
for(int i=1;i<=n;i++){
g[i] = new Vector<>();
}
int u;
for(int i=2;i<=n;i++){
u = nextInt();
g[u].add(i);
}
dfs(1);
int t,k;
while (q--!=0){
t = nextInt();
k = nextInt();
if (k>size[t]){
out.println(-1);
}else {
out.println(ans[index[t]+k-1]);
}
}
out.flush();
}
public static void dfs(int v){
b[v]=true;
size[v]++;
ans[pos++] = v;
index[v] = pos-1;
for(int i=0;i<g[v].size();i++){
int u = g[v].get(i);
if(!b[u]){
dfs(u);
size[v]+=size[u];
}
}
}
}

F:很显然上来就想到了从两个点往中间搜搜一半,但是我写炸了,就找了份代码看了看,对于 “一半”,这个地方  要用 (n/2+m/2)而不是 (n+m)/2  ,ex:1 1 10 10.

还是很好懂的 ,哦还需要知道这么一个事, a^b=c 的话 那么 b^c=a; 原谅我是二进制小白,有几个相关公式可以直接百度

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*; public class Main6 {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer tok;
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); static boolean hasNext() {
while (tok == null || !tok.hasMoreTokens())
try {
tok = new StringTokenizer(in.readLine());
} catch (Exception e) {
return false;
}
return true;
} static String next() {
hasNext();
return tok.nextToken();
} static long nextLong() {
return Long.parseLong(next());
} static int nextInt() {
return Integer.parseInt(next());
} static int n;
static int m;
static long k;
static long ans = 0;
static long a[][];
static Map<Long,Long> map[][];
public static void main(String[] args) {
n = nextInt();
m = nextInt();
k = nextLong();
a = new long[n][m];
map = new Map[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
a[i][j] = nextLong();
map[i][j] = new HashMap<>();
}
}
dfsbe(0,0,0);
dfsend(n-1,m-1,0); out.print(ans);
out.flush();
}
public static void dfsbe(int i,int j,long temp){
if (i>=n||j>=m)
return;
temp ^= a[i][j];
if (i+j==n/2+m/2){
if (map[i][j].get(temp)==null){
map[i][j].put(temp,1l);
}else {
map[i][j].put(temp,map[i][j].get(temp)+1);
}
return;
}
dfsbe(i+1,j,temp);
dfsbe(i,j+1,temp);
}
public static void dfsend(int i,int j,long temp){
if (i<0||j<0)
return;
if (i+j==n/2+m/2){
long num = temp^k;
if (map[i][j].get(num)!=null){
ans+=map[i][j].get(num);
}
return;
}
temp^=a[i][j];
dfsend(i-1,j,temp);
dfsend(i,j-1,temp);
}
}
/**
* 1^1=0
* 0^0=0
* 1^0=1
* 0^1=1
* a ^ b = b ^ a
* a ^ b ^ c = a ^ (b ^ c) = (a ^ b) ^ c;
* d = a ^ b ^ c 可以推出 a = d ^ b ^ c.
* a ^ b ^ a = b.
*/

  

Codeforces Round #498 (Div. 3)的更多相关文章

  1. CodeForces Round #498 Div.3 A. Adjacent Replacements

    http://codeforces.com/contest/1006/problem/A Mishka got an integer array aa of length nn as a birthd ...

  2. Codeforces Round #498 (Div. 3) 简要题解

    [比赛链接] https://codeforces.com/contest/1006 [题解] Problem A. Adjacent Replacements        [算法] 将序列中的所有 ...

  3. Codeforces Round #498 (Div. 3)--E. Military Problem

    题意问,这个点的然后求子树的第i个节点. 这道题是个非常明显的DFS序: 我们只需要记录DFS的入DFS的时间,以及出DFS的时间,也就是DFS序, 然后判断第i个子树是否在这个节点的时间段之间. 最 ...

  4. Codeforces Round #498 (Div. 3) E. Military Problem (DFS)

    题意:建一颗以\(1\)为根结点的树,询问\(q\)次,每次询问一个结点,问该结点的第\(k\)个子结点,如果不存在则输出\(-1\). 题解:该题数据范围较大,需要采用dfs预处理的方法,我们从结点 ...

  5. Codeforces Round #498 (Div. 3) D. Two Strings Swaps (思维)

    题意:给你两个长度相同的字符串\(a\)和\(b\),你可以将相同位置上的\(a\)和\(b\)的字符交换,也可以将\(a\)或\(b\)中某个位置和对应的回文位置上的字符交换,这些操作是不统计的,你 ...

  6. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. SpringBoot(十):读取application.yml下配置参数信息,java -jar启动时项目修改参数

    读取application.yml下配置参数信息 在application.yml文件内容 my: remote-address: 192.168.1.1 yarn: weburl: http://1 ...

  2. Vue.js父与子组件之间传参

    父向子组件传参 例子:App.vue为父,引入componetA组件之后,则可以在template中使用标签(注意驼峰写法要改成componet-a写法,因为html对大小写不敏感,component ...

  3. HashMap代码解析

    hashmap (jdk 1.7)使用 “数组-链表” 方式进行存储,图形化表示如下: 即,前面是一个数组,后面跟一个链表,那么数据结构这个对应到HashMap的代码里面是什么样子的呢? 在HashM ...

  4. ionic 状态栏显示异常 statusBar

    从主分支上新建一个分支开发另一个app, 生成之后手机上显示状态栏异常, 如下图, 只显示了电池的色块, 百思不得其解啊. 各种猜测无果, 对比config.xml, 发现statusBar插件版本不 ...

  5. 记录一次使用VS2015编译错误的原因查找(boost+gdal)

    编译错误说明 在一个解决方案中的项目A中使用到了boost,完全没有问题.在项目B中也使用了boost库,编译的时候就产生了一堆错误. 原因查找 两个项目通过对比,唯一的不同就是项目B使用了gdal库 ...

  6. 百度富文本编辑器整合fastdfs文件服务器上传

    技术:springboot+maven+ueditor   概述 百度富文本整合fastdfs文件服务器上传 详细 代码下载:http://www.demodashi.com/demo/15008.h ...

  7. myBase7 激活方法

    一.引言: 之前使用过一段时间的myBase,那时候发现还不太美观,所以弃用了一段时间,最近看到有myBase7出来,使用了一下感觉还可以,但是只能试用一个月,不过还好找到了破解的方法. 二.破解步骤 ...

  8. WebSocket 理论知识整理

    最近工作用到websocket, 之前虽然也用到了一些简单的东西,但是并没有认真整理一下.所以这次准备了解一下WebSocket. WebSocket产生的背景 WebSocket是一种在单个TCP连 ...

  9. MySQL InnoDB 引擎的持久性与性能

    MySQL 事务的 ACID 特性中,D 代表持久性(Durability):在使用 InnoDB 引擎时,当返回客户端一个成功完成事务的确认时, InnoDB 就会保证数据的一致性,即使该数据在此时 ...

  10. Oracle分析函数-keep(dense_rank first/last)

    select * from criss_sales where dept_id = 'D02' order by sale_date ; 此时有个新需求,希望查看部门 D02 内,销售记录时间最早,销 ...