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 ...
随机推荐
- Go语言排序算法实现
// Algorithm project Algorithm.go package Algorithm // 冒泡排序 func BubbleSort(a []int) { n := len(a) ; ...
- cd4与cd8比值的意义
正常情况下CD4/CD8比值介于1.5—2.5之间,如CD4是每微升血750个,CD8是每微升血460个,这样两者的比值就是1.63. 虽然95%的正常人CD4/CD8的比值都在1以上,但是也有一些正 ...
- 每天一个linux命令(6):cp
1.命令简介 cp(Copy file):将源文件复制至目标文件,或将多个源文件复制至目标目录. 2.用法 cp [选项]... [-T] 源文件 目标文件 或:cp [选项]... 源文件... 目 ...
- 在django中怎么解决没有MySQLdb库的问题
1.安装:pymysql模块 2.在app文件目录下,找到__init__.py文件,在文件中写入下面的代码 #解决django中的MySQLdb模块在python3中没有的问题 import pym ...
- 使用 GeoIP2 获取 IP 的地理位置
1. 准备工作 数据库 : 解析 IP 地理位置的的数据库来自 GeoLite2 开源数据库:https://dev.maxmind.com/geoip/geoip2/geolite2/ . C 语言 ...
- Redis数据结构详解,五种数据结构分分钟掌握
redis数据类型分为:字符串类型.散列类型.列表类型.集合类型.有序集合类型.redis这么火,它运行有多块?一台普通的笔记本电脑,可以在1秒钟内完成十万次的读写操作.原子操作:最小的操作单位,不能 ...
- vue-router2.x使用入门
组件中的路由 <router-link to=""></router-link> 无参数 <router-link to="/ar/1&qu ...
- 整体C#与Sql培训内容及结构
图如果看不清可以右键存图片到本地
- ComputeShader中Consume与AppendStructuredBuffer的使用
上个月写了一篇使用像素shader返回累加信息的Trick:https://www.cnblogs.com/hont/p/9977401.html 后来无意中发现DX11/Compute shader ...
- Java IO 流总结篇
1. 写在前面的话 I/O ,I 是 Input (输入)的缩写,O是Output (输出) 的缩写,众所周知,人与人之间想要沟通交流,就需要讲彼此都能听懂的语言,比如大家都统一说英语. 人类如果想和 ...