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)的更多相关文章

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

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

  3. Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges

    http://codeforces.com/contest/962/problem/F 求没有被两个及以上的简单环包含的边 解法:双联通求割顶,在bcc中看这是不是一个简单环,是的话把整个bcc的环加 ...

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

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

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

  7. D. Merge Equals(from Educational Codeforces Round 42 (Rated for Div. 2))

    模拟题,运用强大的stl. #include <iostream> #include <map> #include <algorithm> #include < ...

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

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

随机推荐

  1. Codeforces Round #219 (Div. 2) D题

    D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes inpu ...

  2. hdu 3062 2-sat

    #include<stdio.h> #include<string.h> #define N 2100 struct node { int u,v,next; }bian[N* ...

  3. codevs1001 舒适的线路

    题目描述 Description Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光.Z小镇附近共有N(1<N≤500)个景点(编号为1,2,3,…,N),这些景点被M(0<M≤ ...

  4. java 远程调用

    1.webservice (soap+http) -aixs -axis2 -xfire—>cxf 2.webservice问题 -基于xml,xml效率,(数据传输效率,xml序列化效率) - ...

  5. 试来试去,WIN下最简单的WIN API开发工具,Pelles C就好啦

    昨晚试过N个,不是太大,就是不容易和WIN API集成. 今早一试就灵了个.... Pelles C. Pelles C是一款windows下的C IDE,支持调试,且为免费.它有一个高效率的链接器, ...

  6. Ubuntu 16.04清楚Dash历史记录

    1.[系统设置]->[安全和隐私]->[文件和应用]->[清除使用数据] 2.清楚播放记录 rm -v ~/.local/share/recently-used.xbel 3.清楚打 ...

  7. MySQL Workbench查看和修改表字段的Comment值

    查看: 选择单个表->[右键]->[Table Inspector] 再选择Columns选项卡即可,把表格拉倒最后一列. 编辑: 选择单个表->[右键]->[Alter Ta ...

  8. sizeof小览

    一.文章来由-一道面试题迁出的探究 我发现我已经形成一种习惯写来由了,以后看博客的时候能够让我回顾起为什么出现这个问题,我用什么方法解决的,既然形成习惯就让这个习惯保持下去吧.今天实验室师姐在看书,一 ...

  9. 适用于app.config与web.config的ConfigUtil读写工具类 基于MongoDb官方C#驱动封装MongoDbCsharpHelper类(CRUD类) 基于ASP.NET WEB API实现分布式数据访问中间层(提供对数据库的CRUD) C# 实现AOP 的几种常见方式

    适用于app.config与web.config的ConfigUtil读写工具类   之前文章:<两种读写配置文件的方案(app.config与web.config通用)>,现在重新整理一 ...

  10. JMeter—丰富报表功能PerfMon插件

    可能有童鞋不知道PerfMon插件是干啥的.这里简要说一下: 在做负载測试时,我们要时刻关注server的CPU.MEM--的使用情况,可是JMeter本身对这些信息是不做收集的,这个时候PerfMo ...