A. Wrong Subtraction

题目大意:

\ 定义一种运算,让你去模拟

题解:

\ 模拟

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <cmath>
inline int max(int a, int b){return a > b ? a : b;}
inline int min(int a, int b){return a < b ? a : b;}
inline int abs(int x){return x < 0 ? -x : x;}
inline void swap(int &x, int &y){int tmp = x;x = y;y = tmp;}
inline void read(int &x)
{
x = 0;char ch = getchar(), c = ch;
while(ch < '0' || ch > '9') c = ch, ch = getchar();
while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
if(c == '-') x = -x;
}
const int INF = 0x3f3f3f3f; int n, k;
int num[20], len; int main()
{
read(n), read(k);
while(n) num[++ len] = n % 10, n /= 10;
int i = 1;
for(;k;-- k)
{
if(num[i]) -- num[i];
else ++ i;
}
for(int j = len;j >= i;-- j) printf("%d", num[j]);
return 0;
}

B. Two-gram

题目大意

\ 找在串S出现次数最多的串S的子串

题解

\ 暴力枚举,比较

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <cmath>
inline int max(int a, int b){return a > b ? a : b;}
inline int min(int a, int b){return a < b ? a : b;}
inline int abs(int x){return x < 0 ? -x : x;}
inline void swap(int &x, int &y){int tmp = x;x = y;y = tmp;}
inline void read(int &x)
{
x = 0;char ch = getchar(), c = ch;
while(ch < '0' || ch > '9') c = ch, ch = getchar();
while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
if(c == '-') x = -x;
}
const int INF = 0x3f3f3f3f; char s[1000], now;
int n, ans, cnt, p; int main()
{
read(n);
scanf("%s", s + 1);
for(now = 1;now < n;++ now)
{
cnt = 0;
for(int j = 1;j < n;++ j)
if(s[now] == s[j] && s[now + 1] == s[j + 1]) ++ cnt;
if(cnt > ans) ans = cnt, p = now;
}
printf("%c%c", s[p], s[p + 1]);
return 0;
}

C. Less or Equal

题目大意:

\ 给你一个数字序列和序列长度n,给你一个非负整数k,问是否存在一个数x,使得序列中小于等于x的元素的个数恰好为k。

题解:

\ 排序后看第k个和第k+1个是否相等。

\ 注意k=0的情况,需要特判。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <cmath>
inline int max(int a, int b){return a > b ? a : b;}
inline int min(int a, int b){return a < b ? a : b;}
inline int abs(int x){return x < 0 ? -x : x;}
inline void swap(int &x, int &y){int tmp = x;x = y;y = tmp;}
inline void read(int &x)
{
x = 0;char ch = getchar(), c = ch;
while(ch < '0' || ch > '9') c = ch, ch = getchar();
while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
if(c == '-') x = -x;
}
const int INF = 0x3f3f3f3f; int n, k, num[1000000]; int main()
{
read(n), read(k);
for(int i = 1;i <= n;++ i) read(num[i]);
std::sort(num + 1, num + 1 + n);
if(!k)
{
if(num[1] <= 1) printf("-1");
else printf("1");
return 0;
}
if(num[k] == num[k + 1]) printf("-1");
else printf("%d", num[k]);
return 0;
}

D. Divide by three, multiply by two

题目大意:

\ 给你一一堆数,让你把他们排序,要求对于相邻两个元素\(a_i,a_{i+1}\),满足\(a_I \times 2 = a_{i+1}\)或\(a_i \div 3 = a_{i+1}\),保证答案存在

题解:

\ 由于2和3互质,所以对于任意一个数\(a\),\(a \div 3\)不可能通过\(\times 2\)与\(\div 3\)操作变成\(a \times 2\)。这也就意味着如果把序列里每个数看做点,每个数向它能变成的序列里的数连一条边,一定是一条链。

\ 暴力建链,找头就行了。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <cmath>
inline long long max(long long a, long long b){return a > b ? a : b;}
inline long long min(long long a, long long b){return a < b ? a : b;}
inline long long abs(long long x){return x < 0 ? -x : x;}
inline void swap(long long &x, long long &y){long long tmp = x;x = y;y = tmp;}
inline void read(long long &x)
{
x = 0;char ch = getchar(), c = ch;
while(ch < '0' || ch > '9') c = ch, ch = getchar();
while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
if(c == '-') x = -x;
}
const long long INF = 0x3f3f3f3f; long long num[1000], nxt[1000], tag[1000], n; int main()
{
read(n);
for(long long i = 1;i <= n;++ i) read(num[i]);
for(long long i = 1;i <= n;++ i)
for(long long j = 1;j <= n;++ j)
if(i == j) continue;
else if(num[i] * 2 == num[j] || num[i] == 3 * num[j]) nxt[i] = j, tag[j] = 1;
for(long long i = 1;i <= n;++ i)
if(!tag[i])
{
while(i) printf("%I64d ", num[i]), i = nxt[i];
return 0;
}
return 0;
}

E. Cyclic Components

题目大意:

\ 给你一张图,问你里面有多个连通分量是一个简单环。

题解:

\ 按照找连通分量的过程dfs,如果一个点度数大于2,那么不可能形成简单环;如果每个点度数都小于2,且dfs过程中走回到某个已经走过的点了,就是简单环。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <cmath>
inline int max(int a, int b){return a > b ? a : b;}
inline int min(int a, int b){return a < b ? a : b;}
inline int abs(int x){return x < 0 ? -x : x;}
inline void swap(int &x, int &y){int tmp = x;x = y;y = tmp;}
inline void read(int &x)
{
x = 0;char ch = getchar(), c = ch;
while(ch < '0' || ch > '9') c = ch, ch = getchar();
while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
if(c == '-') x = -x;
}
const int INF = 0x3f3f3f3f; struct Edge
{
int u, v, nxt;
Edge(int _u, int _v, int _nxt){u = _u, v = _v, nxt = _nxt;}
Edge(){}
}edge[2000010];
int head[2000010], cnt, vis[2000010], n, m, tmp1, tmp2, flag1, flag2, ans, fa[2000010];
inline void insert(int a, int b)
{
edge[++ cnt] = Edge(a, b, head[a]), head[a] = cnt;
}
int find(int x)
{
return x == fa[x] ? x : fa[x] = find(fa[x]);
} void dfs(int x, int pre)
{
vis[x] = 1;
int tot = 0;
for(int pos = head[x];pos;pos = edge[pos].nxt)
{
++ tot;
int v = edge[pos].v;
if(v == pre) continue;
int f1 = find(x), f2 = find(v);
if(fa[f1] == fa[f2]) flag2 = 1;
if(vis[v]) continue;
else fa[f1] = f2;
dfs(v, x);
}
if(tot > 2) flag1 = 0;
} int main()
{
read(n), read(m);
for(int i = 1;i <= n;++ i) fa[i] = i;
for(int i = 1;i <= m;++ i)
read(tmp1), read(tmp2), insert(tmp1, tmp2), insert(tmp2, tmp1);
for(int i = 1;i <= n;++ i)
if(!vis[i])
{
flag1 = 1, flag2 = 0, dfs(i, -1);
ans += flag1 & flag2;
}
printf("%d", ans);
return 0;
}

F. Consecutive Subsequence

题目大意:

\ 给你一个序列,让你找一个单调递增的公差为1的最长子序列。

题解:

\ 先离散化,\(dp[i]\)表示以\(i\)为结尾的最长子序列长度,\(tong[i]\)表示数\(i\)在前面已经确定的\(dp\)状态中,数字为\(ti\)的位置上的最大的\(dp\)值。

\ 转移即可,用链表记录一下方案。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <cmath>
inline int max(int a, int b){return a > b ? a : b;}
inline int min(int a, int b){return a < b ? a : b;}
inline int abs(int x){return x < 0 ? -x : x;}
inline void swap(int &x, int &y){int tmp = x;x = y;y = tmp;}
inline void read(int &x)
{
x = 0;char ch = getchar(), c = ch;
while(ch < '0' || ch > '9') c = ch, ch = getchar();
while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
if(c == '-') x = -x;
}
const int INF = 0x3f3f3f3f; int dp[1000010], num[1000010], pos[1000010], pre[1000010], tong[1000010], n, tot, ans, p;
struct Node
{
int rank, num;
}node[1000010];
bool cmp(Node a, Node b)
{
return a.num < b.num;
}
void dfs(int x)
{
if(!x) return;
dfs(pre[x]);
printf("%d ", x);
}
int main()
{
read(n);
for(int i = 1;i <= n;++ i) read(node[i].num), node[i].rank = i, dp[i] = 1;
std::sort(node + 1, node + 1 + n, cmp);
for(int i = 1;i <= n;++ i)
{
if(node[i].num != node[i - 1].num) ++ tot;
if(node[i].num - node[i - 1].num > 1) ++ tot;
pos[tot] = node[i].num, num[node[i].rank] = tot;
}
for(int i = 1;i <= n;++ i)
{
dp[i] += dp[tong[num[i] - 1]], pre[i] = tong[num[i] - 1];
if(dp[tong[num[i]]] < dp[i])
tong[num[i]] = i;
}
for(int i = 1;i <= n;++ i)
if(dp[i] > ans) ans = dp[i], p = i;
printf("%d\n", ans);
dfs(p);
return 0;
}

针水。

Codeforces Round #479 (Div. 3) 题解 977A 977B 977C 977D 977E 977F的更多相关文章

  1. Codeforces Round #479 (Div. 3)题解

    CF首次推出div3给我这种辣鸡做,当然得写份博客纪念下 A. Wrong Subtraction time limit per test 1 second memory limit per test ...

  2. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  3. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  4. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  5. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  6. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  7. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  8. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  9. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

随机推荐

  1. 互联网公司java面试题(一)

    1.JDK和JRE区别? JDK是整个JAVA的核心,包括了Java运行环境JRE,一堆Java工具和Java基础的类库.通过JDK开发人员将源码文件(java文件)编译成字节码文件(class文 件 ...

  2. 安装JDK9之后eclipse无法启动问题解决办法

    操作系统:MAC OS JDK:1.8.0_131 eclipse:官网最新版 安装jdk的过程很简单,从官网下载之后依次点击就可以了,在终端输入:java -version 可以看到安装后的版本信息 ...

  3. CSS:CSS 总结

    ylbtech-CSS:CSS 总结 1.返回顶部 1. 你已经学习了CSS,下一步学习什么呢? CSS 总结 本教程已向你讲解了如何创建样式表来同时控制多重页面的样式和布局. 你已经学会如何使用 C ...

  4. Delph i2010

    我在习惯Delphi2010 转载   一直留着一个txt文件,不晓得是干嘛的(忘记了),偶然打开一看.乖乖~ 2010 还可以这样玩. 1.循环有了新用法 procedure TForm1.Butt ...

  5. Android Telephony分析(五) ---- TelephonyRegistry详解

    本文紧接着上一篇文章<Android Telephony分析(四) —- TelephonyManager详解 >的1.4小节.从TelephonyRegistry的大部分方法中: 可以看 ...

  6. springboot项目中使用设计模式一策略模式

    策略模式: 使用常用,支付,之前做了微信支付,支付宝支付,然后另外一个同事写了一个银联支付,那么如果代码方法一起就会导致代码不是很好操作所以,采用策略模式进行,同事只需要写一个实现类,就可以了, 在协 ...

  7. HTML_CSS使用

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. MySQL 08章_数据库设计

    一. 关系模型与对象模型之间的对应关系 序号 关系模型:数据库 对象模型:java程序 1 数据表table 实体entity:特殊的java类 2 字段field 属性attribute/字段fie ...

  9. uboot 的启动过程及工作原理

    启动模式介绍 大多数 Boot Loader 都包含两种不同的操作模式:"启动加载"模式和"下载"模式,这种区别仅对于开发人 员才有意义.但从最终用户的角度看, ...

  10. heartbeat 高可用

    转载来自 http://www.cnblogs.com/liwei0526vip/p/6391833.html 使用HeartBeat实现高可用HA的配置过程详解 一.写在前面 HA即(high av ...