Codeforces Round #496 (Div. 3)
一如既往地四题。。。好久没切了 有点犯困了明显脑子感觉不够灵活。
为了熟练度还是用java写的,,,导致观赏性很差。。。我好不容易拉了个队友一起切结果过掉a就tm挂机了!!!
A题竟然卡了,,,用了十分钟,幸好我蓝了,不然这罚时怕不是要gg。
A:
想了很多乱七八糟的法子,蓦然回首,还是暴力大法好。
把所有 ai==1 的点的下标全存进去, 然后对 a(n-1) 判断一下是否 为 1 就行, 我不知道怎么打带下标的数组啊啊啊,
int n = nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = nextInt();
}
int num = 0;
int b[] = new int[n];
for(int i=0;i<n;i++){
if (a[i]==1)
b[num++]=i;
}
out.println(num);
for(int i=0;i<num;i++){
if (b[i]==0){
continue;
}else
out.print(a[b[i]-1]+" ");
}
if (a[n-1]==1)
out.print(1);
else {
out.print(a[n-1]);
}
out.flush();
}
main 方法
B:一眼秒了,java写的话就跟a+b一样简单了。。。
找两个字符串的最长相同后缀就完了。代码我就懒得放了
C:cnm毒瘤啊啊啊啊卡了好久才找到bug。。。用的map和set,到最后直接输出的set.size(),但是没考虑到去不掉的元素会有相同的。我是傻逼
数组 c 是自己打的表 从1到2的29次方,,,因为stl里的各种方法可能不太一样,就比较难懂,但大体思路是一样的,话说我这种能在java和c++中间自由转换的能力可真是厉害呢
看到一个实验室的小伙伴竟然都没交几发试试,详细地说一下, set 存所有的元素,因为无法知道个数, 也用 map 存一遍 (用来 判断 4,4 这种一样的情况),
首先我们发现这样一个事实: 如果一个较大的元素可以留下,那么 大于等于它自身的2的整数次幂 减去 它自己 得到 的数 一定存在set里 。(如果 513 可以留下,那么 511 一定存在) 所以直接走一遍就行。能找到配对的在set中全部 remove 掉, 到最后 遍历一边 set,通过 map 得到 set中 元素的 个数总和。
public static void main(String[] args) {
int n = nextInt();
int a[] = new int[n];
Map<Integer,Integer> map = new HashMap<Integer, Integer>();
Set<Integer> set = new HashSet<Integer>();
for(int i=0;i<n;i++){
a[i] = nextInt();
set.add(a[i]);
if (map.containsKey(a[i])){
map.put(a[i],map.get(a[i])+1);
}else {
map.put(a[i],1);
}
}
for(int i=0;i<n;i++) {
int temp = -1;
for (int j = 0; j < c.length; j++) {
if (c[j] >= a[i]) {
temp = c[j] - a[i];
break;
}
}
if (temp==0){
if (map.get(a[i])>1){
set.remove(a[i]);
}
}else {
if (map.containsKey(temp)){
set.remove(a[i]);
set.remove(temp);
}
}
}
int ans = 0;
Iterator<Integer> it = set.iterator();
while (it.hasNext()){
ans+=map.get(it.next());
}
out.print(ans);
out.flush();
}
D:
在点11卡了一会,特别囍的是 点了下记录,当时有5个d题,结果全wa点11。。普通贪心 很好想到,遇到 3的整数倍 或者 0 就拿出来。 另外 能被3 整除的 数 那么它各位数的和一定能被三整除,所以我们可以 用一个 sum来记录
以下错误想法千万不要看:wa了之后 瞎试出来一组样例 110112,,, 按照我错误的贪心 , 112 这个数 其实是 没答案的,因为 sum 分别等于 1,2,4,发现这个bug之后就很容易修改了,还是 map 存一下就ok
public static void main(String[] args) {
String s = next();
int n = s.length();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = s.charAt(i)-'0';
}
int ans = 0;
int sum = 0;
int y[] = new int[3];
for(int i=0;i<n;i++){
if (a[i]%3==0){
y[1]=0;
y[2]=0;
sum=0;ans++;
}else if (a[i]==0){
y[1]=0;
y[2]=0;
sum=0;ans++;
}else {
sum+=a[i];
y[sum%3]++;
if (sum%3==0){
y[1]=0;
y[2]=0;
sum=0;
ans++;
}else {
if (y[sum%3]>1){
y[1]=0;
y[2]=0;
sum=0;
ans++;
}
}
}
}
out.print(ans);
out.flush();
}
main 方法
E题时间太短了没来得及细想,虽然我觉着细想也做不出来 ,学长们因为今天要考试都没打也没有靠谱的代码能看,先这样吧,话说在家里切题可真舒服,,不开空调一点也不热
Codeforces Round #496 (Div. 3)的更多相关文章
- Codeforces Round #496 (Div. 3) ABCDE1
//B. Delete from the Left #include <iostream> #include <cstdio> #include <cstring> ...
- CodeForces -Codeforces Round #496 (Div. 3) E2. Median on Segments (General Case Edition)
参考:http://www.cnblogs.com/widsom/p/9290269.html 传送门:http://codeforces.com/contest/1005/problem/E2 题意 ...
- Codeforces Round #496 (Div. 3 ) E1. Median on Segments (Permutations Edition)(中位数计数)
E1. Median on Segments (Permutations Edition) time limit per test 3 seconds memory limit per test 25 ...
- Codeforces Round #496 (Div. 3) F - Berland and the Shortest Paths
F - Berland and the Shortest Paths 思路:还是很好想的,处理出来最短路径图,然后搜k个就好啦. #include<bits/stdc++.h> #defi ...
- Codeforces Round #496 (Div. 3) E2 - Median on Segments (General Case Edition)
E2 - Median on Segments (General Case Edition) 题目大意:给你一个数组,求以m为中位数的区间个数. 思路:很巧秒的转换,我们把<= m 数记为1, ...
- Codeforces Round #496 (Div. 3) E1. Median on Segments (Permutations Edition) (中位数,思维)
题意:给你一个数组,求有多少子数组的中位数等于\(m\).(若元素个数为偶数,取中间靠左的为中位数). 题解:由中位数的定义我们知道:若数组中\(<m\)的数有\(x\)个,\(>m\)的 ...
- Codeforces Round #496 (Div. 3) D. Polycarp and Div 3 (数论)
题意:给你一个巨长无比的数,你可以将这个数划成任意多个部分,求这些部分中最多有多少个能被\(3\)整除. 题解:首先我们遍历累加每个位置的数字,如果某一位数或者累加和能被\(3\)整除(基础知识,不会 ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- SharePoint 配置PowerShell任务计划
前言 最近,有这么个需求,需要定时为SharePoint更新内容,所以,就想到了PowerShell命令和任务计划(Windows自带的功能,英文叫Task Schedule,在开始菜单里就能找到), ...
- java调用sap的webservice(需要登录验证)
1.Base64.java /* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache ...
- LSTM Networks
Understanding LSTM Networks Recurrent Neural Networks Humans don’t start their thinking from scratch ...
- AxWindowsMediaPlayer控件的使用
首先要知道如何将控件添加到工具箱中,步骤如下: “工具箱”中单击右键,选择“选择项”菜单,打开“选择工具箱项”窗口,选择“COM组件”标签,在列表中找到并勾选“Windows Media Player ...
- 【Spring】Springboot监听器,启动之后初始化工作
package com.laplace.laplace.common.starter.config; import java.io.IOException; import org.slf4j.Logg ...
- 遇到一个git branch很奇怪的问题
最近,同事做了一个自动化的打包平台,但我发现里面的分支竟然有重复的,还有一些已经删除的branch. 比如,我已经删除了一个 test分支,在工程 game 目录下(已输入 git pull),输入: ...
- Guava-Objects使用
前言 Java中的Object提供了很多方法供所有的类使用,特别是toString.hashCode.equals.getClass等方法,在日常开发中作用很大,Guava中包含Objects类,其提 ...
- jquery中选择器input:hidden和input[type=hidden]的区别
关于选择器:hidden的说明,在jquery说明文档中是这样说的:匹配所有不可见元素,或者type为hidden的元素.而[type=hidden]是查找所有type属性等于hidden的元素.两者 ...
- Android Studio集成到Genymotion模拟器
环境:Mac Android Studio 一.下载Android Studio 下载地址:http://www.android-studio.org/ 这个的安装没啥好说的了,基本的. 二.下载Ge ...
- Mybatis(三) 映射文件详解
前面说了全局配置文件中内容的详解,大家应该清楚了,现在来说说这映射文件,这章就对输入映射.输出映射.动态sql这几个知识点进行说明,其中高级映射(一对一,一对多,多对多映射)在下一章进行说明. 一.输 ...