一如既往地四题。。。好久没切了 有点犯困了明显脑子感觉不够灵活。

为了熟练度还是用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)的更多相关文章

  1. Codeforces Round #496 (Div. 3) ABCDE1

    //B. Delete from the Left #include <iostream> #include <cstdio> #include <cstring> ...

  2. 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 题意 ...

  3. 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 ...

  4. Codeforces Round #496 (Div. 3) F - Berland and the Shortest Paths

    F - Berland and the Shortest Paths 思路:还是很好想的,处理出来最短路径图,然后搜k个就好啦. #include<bits/stdc++.h> #defi ...

  5. Codeforces Round #496 (Div. 3) E2 - Median on Segments (General Case Edition)

    E2 - Median on Segments (General Case Edition) 题目大意:给你一个数组,求以m为中位数的区间个数. 思路:很巧秒的转换,我们把<= m 数记为1, ...

  6. Codeforces Round #496 (Div. 3) E1. Median on Segments (Permutations Edition) (中位数,思维)

    题意:给你一个数组,求有多少子数组的中位数等于\(m\).(若元素个数为偶数,取中间靠左的为中位数). 题解:由中位数的定义我们知道:若数组中\(<m\)的数有\(x\)个,\(>m\)的 ...

  7. Codeforces Round #496 (Div. 3) D. Polycarp and Div 3 (数论)

    题意:给你一个巨长无比的数,你可以将这个数划成任意多个部分,求这些部分中最多有多少个能被\(3\)整除. 题解:首先我们遍历累加每个位置的数字,如果某一位数或者累加和能被\(3\)整除(基础知识,不会 ...

  8. 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 ...

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

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

随机推荐

  1. 怎样让两个DIV在同一水平线上面显示

    css定义第二个div. float:right或者left. margin-top:0px 确保第二个DIV的宽度.如果宽度宽的话,会自动到下方的.

  2. Cocos Creator下删除AnySDK步骤

    1.删除 frameworks/runtime-src/Classes 下的 jsb_anysdk_basic_conversions.cpp manualanysdkbindings.cpp jsb ...

  3. Dockerfile的 RUN和CMD

    在创建Dockerfile的时候,RUN和CMD都是很重要的命令.它们各自的作用分别如下: RUNRUN命令是创建Docker镜像(image)的步骤,RUN命令对Docker容器( containe ...

  4. 10分钟上手图数据库Neo4j

    随着互联网不断的发展,传统的关系型数据库如oracle,mysql已经难以支撑现下大数据量,高并发的场景了.于是,NoSQL横空出世,有像cassandra这样的column-based,像Mongo ...

  5. Unity3D修改LWRP,HDRP的几项小问题及解决

    最近在看Book of the Dead的demo,其中对HDPR进行修改以构建自己的SRP,于是自己尝试了下.. 一般直接去Github下载对应unity版本的SRP工程: https://gith ...

  6. Atitit 3种类型的公司:运营驱动型;产品驱动型; 技术驱动型。

    Atitit  3种类型的公司:运营驱动型:产品驱动型: 技术驱动型. 领导驱动,产品驱动,运营驱动还是工程师驱动 3种类型的公司: 一种是运营驱动型: 一种是产品驱动型: 一种技术驱动型. 运营驱动 ...

  7. Java JDK下载、安装与环境变量配置

    https://blog.csdn.net/siwuxie095/article/details/53386227 https://blog.csdn.net/liudongdong19/articl ...

  8. Fluent动网格【10】:区域运动案例

    本案例主要描述如何在Fluent中处理包含了公转和自转的复合运动.涉及到的内容包括: 多区域模型创建 滑移网格设置 区域运动UDF宏DEFINE_ZONE_MOTION 案例描述 案例几何如图所示. ...

  9. crawler_exa1

    编辑中... #! /usr/bin/env python # -*- coding:utf-8 -*- # Author: Tdcqma ''' 网页爬虫,版本 2017-09-20 21:16 ' ...

  10. 为什么要使用NoSQL

    转载自:http://www.infoq.com/cn/news/2011/01/nosql-why [编者按]NoSQL在2010年风生水起,大大小小的Web站点在追求高性能高可靠性方面,不由自主都 ...