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

为了熟练度还是用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. jQuery Distpicker插件 省市区三级联动 动态赋值修改地址

    在获取创建页面数据后需要在编辑页面调取之前提交的数据,在使用这个插件后发现无法动态赋值,查找资料后发现需要先销毁实例,$(’#target’).distpicker(‘destroy’); 第一步 引 ...

  2. Spring Boot 中application.yml与bootstrap.yml的区别

    其实yml和properties文件是一样的原理,且一个项目上要么yml或者properties,二选一的存在. 推荐使用yml,更简洁. bootstrap与application1.加载顺序这里主 ...

  3. How to copy the contents of std::vector to c-style static array,safely?

    [问题] I am getting warning when using the std copy function. I have a byte array that I declare. byte ...

  4. Javascript中页面加载完成后优先执行顺序

    Javascript中页面加载完成后优先执行顺序 document优先于windowwindow优先于element //document加载完成执行方法体 document.addEventList ...

  5. t-SNE 层次聚类

    https://zhuanlan.zhihu.com/p/28967965 https://haojunsui.github.io/2016/07/16/scipy-hac/

  6. 【PMP】易混淆知识点

    一.混淆概念 德尔菲技术 德尔菲技术是组织专家达成一致意见的一种方法.项目专家匿名参与其中.组织者使用调查问卷就重要的项目议题征询意见,然后对专家的答卷进行归纳,并把结果反馈给专家做进一步评论.这个过 ...

  7. Ubuntu18.04下的模拟神器RetroArch

    安装 直接通过apt安装 sudo add-apt-repository ppa:libretro/stable sudo apt update sudo apt install retroarch ...

  8. Implementation of Message Receiver

  9. C语言截取从某位置开始指定长度子字符串方法

    c语言标准库没有截取部分字符串的函数,为啥?因为用现有函数strncpy,很容易做到! ] = {""}; "}; strncpy(dest, src, ); puts( ...

  10. 星云的Linux专用学习手册

    Centos 7 为例 1. 查看操作系统信息 uname -a 执行效果如下: [fairy@localhost ~]$ uname -a Linux localhost.localdomain - ...