Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 A. Be Positive 题意: 给出n个数,看是否正数的个数过半或者负数的个数过半. 题解:水题,代码如下: #include <bits/stdc++.h> using namespace std; ; int n; double a[N]; int main(){ ios::sync_…
http://codeforces.com/contest/1129/problem/C #include<bits/stdc++.h> #define fi first #define se second #define INF 0x3f3f3f3f #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define pqueue priority_queue #define NEW(a,b) memset(a,b,s…
A. Be Positive 链接:http://codeforces.com/contest/1130/problem/A 题意: 给一段序列,这段序列每个数都除一个d(−1e3≤d≤1e3)除完后,如果正数的个数可以大于序列长度的一半输出这个d,否则输出0 思路: 直接找正数和负数的个数,正数个数大于一半输出1,负数个数大于一半输出-1,都不大于一半长度输出0就好了 代码: #include<bits/stdc++.h> using namespace std; int main() {…
A. Be Positive 题意:给出一个数组 每个树去除以d(d!=0)使得数组中大于0的数 大于ceil(n/2) 求任意d 思路:数据小 直接暴力就完事了 #include<bits/stdc++.h> using namespace std; ; double a[maxn]; int main(){ int n; scanf("%d",&n); ;i<n;i++){ scanf("%lf",&a[i]); } ); fo…
题意:给你n个01字符,每次问你前缀的所有本质不同的子串,由摩斯密码组成的方案数和. 题解:离线处理,把字符建sam,通过topo序来dp计算每个节点表示的子串方案数的和.统计答案时,把n个字符挨个匹配过去,把所有经过的节点加上方案数,还有每个节点的fa链,也要统计(因为是当前串的后缀),用一个vis标记访问过没有.复杂度O(n*32),于是这题n能出到1e6 //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pragma GCC op…
A - Toy Train 很显然,一个站有多少个糖,那么就要从这个点运多少次.设第i个点有\(a_i\)个糖,那么就要转\(a_i-1\)圈,然后再走一段.很显然最后一段越小越好. 然后枚举起点后,每个点的答案就是起点到他的距离加上再走的距离.然后取个max就好了. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<cctype> #d…
A. Toy Train 时间限制:2 seconds 内存限制:256 megabytes 题意 有编号111~n(n≤5000)n(n\le 5000)n(n≤5000)的车站顺时针呈环排列,有m(m≤20000)m(m\le 20000)m(m≤20000)个糖果需要运送到指定位置.每个糖果由(a[i],b[i])(a[i],b[i])(a[i],b[i])表示,其中a[i]≠b[i]a[i]=\not b[i]a[i]≠​b[i],指这个糖果最初位置和需要运送到的位置.列车只能顺时针…
layout: post title: Codeforces Round 542 (Div. 2) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces - 并查集 --- 传送门 前三题太简单不写 D.Toy Train (贪心) 题意 有n个车站,按照环前进,有m条要求从x送到y,每次从x最多能拿一个糖,输出在第i个车站出发最少需要多少时间完成所有要求 (注意车的容量无穷) 思路 所以我们直接枚举每…
Codeforces Round #542 abstract I决策中的独立性, II联通块染色板子 IIIVoronoi diagram O(N^2 logN) VI环上距离分类讨论加取模,最值中的决定性元素 V代数构造 B 题意 2n个数排成一行,1..n各出现两次,两个人分别从1按顺序走到n(每个数只能被一个人路过),问他们两个人的距离和的最小值(两个数之间的距离等于他们位置(下标)值差)? 题解 将每个数的两个位置用pair存起来(eg : pos[1].x , pos[1].y). 首…
int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可以区分出未赋值和值为0的区别,int则无法表达出未赋值的情况,例如,要想表达出没有参加考试和考试成绩为0的区别,则只能使用Integer.在JSP开发中,Integer的默认为null,所以用el表达式在文本框中显示时,值为空白字符串,而int默认的默认值为0,所以用el表达式在文本框中显示时,结果…
ps:python的round()和javascript的round()的比较: javascript:Math.round():正常的标准舍入,就像我们学的数学课本上面的规则 python:python中的round()会根据版本的不同而出现不同的结果.整体的是最靠近当前偶数的规则 01:当小数部分只为0.5时,整数部分如果为奇数则进1,如果为偶数则舍去小数部分 print(round(-3.5)) #-4 print(round(-4.5)) #-4 02:小数部分不为0.5时,按标准的四舍…
Codeforces Round 1129 这场模拟比赛做了\(A1\).\(A2\).\(B\).\(C\),\(Div.1\)排名40. \(A\)题是道贪心,可以考虑每一个站点是分开来的,把目的地最小编号的留到最后,所以答案稍微算一下就行了. \(B\)题是道找规律,首先可以很容易地发现只要前面弄个负数的开头,错误算法就会忽略掉这一个值,所以利用这个来构造答案.(最讨厌构造题了)然后推导一番式子就会发现如果我们将第一个值放-1,则 \(\sum_{i=2}^na_i=k+n\), 再更改一…
C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终点,只允许挖一条穿越海的隧道,假设隧道连接的两个陆地分别为(x1,y1),(x2,y2),则挖隧道的花费为\((y1-x1)*(y1-x1)+(y2-x2)*(y2-x2)\) 题解 分别找出和起点,和终点连接的陆地(找联通块),枚举两个点维护最小值 代码 #include<bits/stdc++.h&…
链接:https://codeforces.com/contest/1130/problem/B 题意: 给定n和 2 * n个数,表示i位置卖ai层蛋糕, 有两个人在1号,必须严格按照1-n的顺序买蛋糕,同时每个店只买一个蛋糕 . 求所需的最短时间. 思路: 将每种蛋糕对应位置记录在二维数组. 从1-n挨个买,根据上一次的位置算出消耗. 代码: #include <bits/stdc++.h> using namespace std; typedef long long LL; const…
链接:https://codeforces.com/contest/1130/problem/A 题意: 给n个数,找出一个非0整数d,使所有n个数除以整数d后,数组中正数的数量>= n/2. 如果不存在d,输出0. 思路: 记录正数和负数的数量,只有有一个满足就输出1或-1,否则为0. 代码: #include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { int n, a; cin &g…
链接:https://codeforces.com/contest/1130/problem/D1 题意: 给n个车站练成圈,给m个糖果,在车站上,要被运往某个位置,每到一个车站只能装一个糖果. 求从每个位置开车的最小的时间. 思路: vector记录每个位置运送完拥有糖果的时间消耗,为糖果数-1 * n 加上消耗最少时间的糖果. 对每个起点进行运算,取所有点中的最大值. 代码: #include <bits/stdc++.h> using namespace std; typedef lon…
链接:https://codeforces.com/contest/1130/problem/C 题意: 给一个n*n的图,0表示地面,1表示水,给出起点和终点, 现要从起点到达终点,有一次在两个坐标间创立隧道的机会,消耗为(x1 - x2)^2 + (y1 - y1)^2. 求出最小的消耗,如果直接能走到,则消耗为0. 思路: bfs求出起点和终点分别能到达的点,枚举每一种情况,取最小值即可. 代码: #include <bits/stdc++.h> using namespace std;…
开学了住校了打不了深夜场 好难受啊QwQ A 显然对于每个起点,我们只需要贪心记录这个起点出发出去的糖果数量以及离自己最近的糖果 因为这个起点最后一次装载糖果一定是装载终点离自己最近的那个糖果 $ O(n^2)$暴力贪心即可 有线性做法懒得写了 #include<ctime> #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algo…
A:显然对于起点相同的糖果,应该按终点距离从大到小运.排个序对每个起点取max即可.读题花了一年还wa一发,自闭了. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define N…
B. Problems for Round 题目连接: http://www.codeforces.com/contest/673/problem/B Description There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficult…
连接在这里,->点击<- A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and ther…
B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty,…
题目链接: http://codeforces.com/contest/673/problem/D 题意: 给四个不同点a,b,c,d,求是否能构造出两条哈密顿通路,一条a到b,一条c到d. 题解: 构造法,看例子: input: 5 6 5 2 4 1 output: 5 4 3 1 2 4 5 3 2 1 所以只要满足k>=n+1,就可以构造出来答案. #include<iostream> #include<cstring> #include<cstdio>…
题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> using namespace std; ; const int…
题目链接: http://codeforces.com/contest/669/problem/D 题意: 给你一个初始序列:1,2,3,...,n. 现在有两种操作: 1.循环左移,循环右移. 2.1,2位置交换,3,4位置交换,...,n-1,n位置交换 现在问执行了q次操作之后序列是什么,每次操作可以是两种操作的任意一种 题解: 我们把数列按位置的奇偶分为两堆,无论哪种操作,始终都还是这两堆,最多就是整堆的对换和一个堆内部的偏移. 所以我们只要记录第一个位置和第二个位置的数的变化(相当于每…
D. Bear and Two Paths 题目连接: http://www.codeforces.com/contest/673/problem/D Description Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same p…
C. Bear and Colors 题目连接: http://www.codeforces.com/contest/673/problem/C Description Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n.…
A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or…
C. Little Artem and Random Variable 题目连接: http://www.codeforces.com/contest/668/problem/C Description Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them. Cons…
E. Little Artem and Time Machine 题目连接: http://www.codeforces.com/contest/669/problem/E Description Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply thi…