Educational Codeforces Round 42 (Rated for Div. 2)
A. Equator(模拟)
找权值的中位数,直接模拟。。
代码写的好丑qwq。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAXN = 1e6 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N;
int a[MAXN];
main() {
#ifdef WIN32
// freopen("a.in", "r", stdin);
#endif
int N = read(), sum = ;
for(int i = ; i <= N; i++) a[i] = read(), sum += a[i];
int now = ;
for(int i = ; i <= N; i++) {
now += a[i];
if(!(sum & )) {
if(now >= sum / ) {
printf("%d", i); return ;
}
} else {
if(now > sum / ) {
printf("%d", i); return ;
}
}
}
}
A
B. Students in Railway Carriage(贪心)
直接贪心放,如果是偶数的话肯定是两种各放一半
如果是奇数的话,应该在都放一半的基础上,把多的放在最后一个
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAXN = 1e6 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N;
char s[MAXN];
main() {
#ifdef WIN32
// freopen("a.in", "r", stdin);
#endif
int N = read(), A = read(), B = read();
if(A < B) swap(A, B);
scanf("%s", s + );
int last = ;
int ans = ;
s[N + ] = '*';
for(int i = ; i <= N + ; i++) {
if(s[i] == '*') {
int len = i - last - ;
ans += min(len / , A) + min(len / , B);
A -= min(len / , A); B -= min(len / , B);
if((len & ) && A > ) A--, ans++;
if(A < B) swap(A, B);
last = i;
}
} printf("%d", ans);
}
B
C. Make a Square(数论,暴力)
首先把所有平方数预处理出来
然后对于输出的数的各个位分解出来,
枚举所有的平方数,算出最少需要删几个
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
const int MAXN = 1e6 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int po[MAXN], tot = , N, P[MAXN], Pnum = ;
int check(int val) {
int times = ;
for(int i = ; i <= Pnum; i++) {
if(P[i] == val % ) {
val /= , times++;
}
if(val == ) {
return Pnum - times;
}
}
if(val != ) return -;
else return Pnum - times;
}
main() {
#ifdef WIN32
// freopen("a.in", "r", stdin);
#endif
for(int i = ; ; i++) {
po[++tot] = i * i;
if(po[tot] > * 1e9) break;
}
N = read();
int x = N;
while(x) P[++Pnum] = x % , x /= ;
int ans = 1e9;
for(int i = ; i <= tot; i++) {
int num = check(po[i]);
if(num != -) ans = min(ans, num);
}
printf("%I64d", ans == 1e9 ? - : ans);
}
C
D. Merge Equals(堆)
用优先队列维护每个数的位置和权值(权值相同的时候位置小的在前面)
然后每次取出前两个,如果相同就合成完再放回去,否则统计答案
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define int long long
using namespace std;
const int MAXN = 1e6 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N;
struct Node {
int pos, val;
bool operator < (const Node &rhs) const {
return val == rhs.val ? pos > rhs.pos : val > rhs.val;
}
};
priority_queue<Node>q;
int ans[MAXN];
void work() {
while(q.size() >= ) {
Node x = q.top(); q.pop();
Node y = q.top(); q.pop();
if(x.val != y.val) {q.push(y); ans[x.pos] = x.val; continue;}
q.push((Node){y.pos, x.val * });
}
while(q.size() != ) ans[q.top().pos] = q.top().val, q.pop();
}
main() {
#ifdef WIN32
// freopen("a.in", "r", stdin);
#endif
N = read();
for(int i = ; i <= N; i++)
q.push((Node){i, read()});
work();
int num = ;
for(int i = ; i <= N; i++)
if(ans[i] != )
num++;
printf("%I64d\n", num);
for(int i = ; i <= N; i++)
if(ans[i] != )
printf("%I64d ", ans[i]);
}
D
Educational Codeforces Round 42 (Rated for Div. 2)的更多相关文章
- Educational Codeforces Round 42 (Rated for Div. 2) E. Byteland, Berland and Disputed Cities
http://codeforces.com/contest/962/problem/E E. Byteland, Berland and Disputed Cities time limit per ...
- Educational Codeforces Round 42 (Rated for Div. 2) D. Merge Equals
http://codeforces.com/contest/962/problem/D D. Merge Equals time limit per test 2 seconds memory lim ...
- Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges
http://codeforces.com/contest/962/problem/F 求没有被两个及以上的简单环包含的边 解法:双联通求割顶,在bcc中看这是不是一个简单环,是的话把整个bcc的环加 ...
- Educational Codeforces Round 42 (Rated for Div. 2) C
C. Make a Square time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Educational Codeforces Round 42 (Rated for Div. 2) B
B. Students in Railway Carriage time limit per test 2 seconds memory limit per test 256 megabytes in ...
- Educational Codeforces Round 42 (Rated for Div. 2) A
A. Equator time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- D. Merge Equals(from Educational Codeforces Round 42 (Rated for Div. 2))
模拟题,运用强大的stl. #include <iostream> #include <map> #include <algorithm> #include < ...
- C Make a Square Educational Codeforces Round 42 (Rated for Div. 2) (暴力枚举,字符串匹配)
C. Make a Square time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...
- D Merge Equals Educational Codeforces Round 42 (Rated for Div. 2) (STL )
D. Merge Equals time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...
随机推荐
- 【Codeforces 427C】Checkposts
[链接] 我是链接,点我呀:) [题意] 环里面的点只需要一个点就能全都保护 问你最少需要多少花费以及最少的点才能将所有的点都保护 [题解] 有向图的强连通分量求出所有的联通分量 显然每个联通分量里面 ...
- mdbtools使用
1.导入数据库到mysql(将key.mdb导入MySQL的test数据库,此时只导入表结构) mdb-schema key.mdb mysql | mysql -u root -p test 2.将 ...
- codevs——1517 求一次函数解析式
1517 求一次函数解析式 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题解 题目描述 Description 相信大家都做过练习册上的这种 ...
- Ubuntu 16.04错误:The update information is outdated this may be caused by network...的问题解决
说明:这个问题没有最终的解决方案,只有不断的尝试. 错误: The update information is outdated this may be caused by network probl ...
- git SSL certificate problem: unable to get local issuer certificate
cmd 命令行中输入 git config --global http.sslVerify false 之后再进行操作
- android_handler(一)
仅仅是一个简单的handler的样例,目的就是对handler有一个初步的接触. 在layout上加入一个button,点击按钮,然后打印出利用handler传送的数据.(都是执行在mainthrea ...
- NSDate 格式化 及 互转
/* NSDateFormatter的作用 1.NSString -> NSDate 2.NSDate -> NSString */ void fmt_date_to_string(); ...
- hdu 4549 M斐波那契数列(矩阵高速幂,高速幂降幂)
http://acm.hdu.edu.cn/showproblem.php?pid=4549 f[0] = a^1*b^0%p,f[1] = a^0*b^1%p,f[2] = a^1*b^1%p... ...
- LeetCode 645. Set Mismatch (集合不匹配)
The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of ...
- error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
[root@luozhonghua ~]# /usr/bin/mysqladmin -u root password 'aaaaaa' /usr/bin/mysqladmin: connect t ...