CODE FESTIVAL 2016 qual A

A - CODEFESTIVAL 2016

……

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 500005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
string s;
void Solve() {
cin >> s;
cout << s.substr(0,4) << " " << s.substr(4) << endl;
} int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

B - 仲良しうさぎ / Friendly Rabbits

……

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
int a[MAXN];
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) {
read(a[i]);
}
int ans = 0;
for(int i = 1 ; i <= N ; ++i) {
if(a[a[i]] == i) ++ans;
}
out(ans / 2);enter;
} int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

C - 次のアルファベット / Next Letter

先从前面到后面把能变成a的都变成a,然后把所有的操作给最后一个字母即可

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int K,N;
char s[MAXN];
void Solve() {
scanf("%s",s + 1);
read(K);
N = strlen(s + 1);
for(int i = 1 ; i <= N ; ++i) {
int t = s[i] - 'a';
if(t != 0) {
if(K >= 26 - t) {s[i] = 'a';K -= (26 - t);}
}
}
K %= 26;
int t = s[N] - 'a';
t = (t + K) % 26;
s[N] = 'a' + t;
for(int i = 1 ; i <= N ; ++i) {
putchar(s[i]);
}
enter;
} int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

D - マス目と整数 / Grid and Integers

\(b_{i,j} + b_{i + 1,j + 1} = b_{i,j + 1} + b_{i + 1,j}\)

可以得到\(b_{i,j + 1} - b_{i,j} = b_{i + 1,j + 1} - b_{i + 1,j}\)

同样的横列也可以得到

\(b_{i + 1,j} - b_{i,j} = b_{i + 1,j + 1} - b_{i,j + 1}\)

也就是我们可以找到两个数列\(x_{1}..x_{R}\)

和\(y_{1}..y_{C}\)

\(b_{i,j} = x_{i} + y_{j}\)

是满足对角线两列相加相等的

然后我们把\(x_{i} + y_{j}\)固定的连一条边,一个联通块内固定一个便可以使得所有点都标记上值,我们在标记的过程中同时看是否合法即可

那么如何保证非负呢

我们在一个联通块内,如果最小的x和最小的y相加是正的,以为一个联通块内y增加1会使得所有的x减少1,x增加1同理,这种情况使得所有的x和y都变成非负的,显然合法

如果最小的x和最小的y是负的,那么就不合法了,也无法调整了

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int R,C,N;
struct node {
int to,next;
int64 val;
}E[MAXN * 10];
int head[MAXN],sumE;
int64 val[MAXN],xmin,ymin;
bool vis[MAXN];
bool used[MAXN];
void add(int u,int v,int64 c) {
E[++sumE].to = v;
E[sumE].next = head[u];
E[sumE].val = c;
head[u] = sumE;
}
bool dfs(int u) {
vis[u] = 1;
for(int i = head[u] ; i ; i = E[i].next) {
int v = E[i].to;
if(!vis[v]) {
val[v] = E[i].val - val[u];
if(!dfs(v)) return false;
}
else {
if(val[u] + val[v] != E[i].val) return false;
}
}
return true;
}
void find_min(int u) {
used[u] = 1;
if(u <= R) xmin = min(xmin,val[u]);
if(u > R) ymin = min(ymin,val[u]);
for(int i = head[u] ; i ; i = E[i].next) {
int v = E[i].to;
if(!used[v]) find_min(v);
}
}
void Solve() {
read(R);read(C);read(N);
int a,b;int64 c;
for(int i = 1 ; i <= N ; ++i) {
read(a);read(b);read(c);
add(a,b + R,c);add(b + R,a,c);
}
for(int i = 1 ; i <= R + C ; ++i) {
if(!vis[i]) {
if(!dfs(i)) {puts("No");return;}
xmin = 1e18,ymin = 1e18;
find_min(i);
if(xmin + ymin < 0) {puts("No");return;}
}
}
puts("Yes");
} int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

E - LRU パズル / LRU Puzzle

假如对一个序列进行了操作,这个序列最后的样子是未操作的数仍然有序放在最后,然后被操作的数从后往前扫描操作序列,第一个出现的数排在最前,重复出现的直接忽略即可

那么我们对假如Q次放到同一序列里,也做一遍这个操作,会得到一个最终序列,这个序列就是我们必须让每一个都变成这样的序列

序列从末尾到前非单调下降的第一个位置之前,就是每个序列都必须有的一段操作序列

于是我们从后往前扫看看这种操作序列最多是否超过N个即可

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,M,Q;
int a[MAXN],pos[MAXN],reserve[MAXN];
bool vis[MAXN];
vector<int> v;
void Solve() {
read(N);read(M);read(Q);
v.pb(0);
for(int i = 1 ; i <= Q ; ++i) {read(a[i]);}
for(int i = Q ; i >= 1 ; --i) {
if(!vis[a[i]]) {
v.pb(a[i]);
vis[a[i]] = 1;
}
}
for(int i = 1 ; i <= M ; ++i) {
if(!vis[i]) v.pb(i);
}
for(int i = 1 ; i <= M ; ++i) pos[v[i]] = i;
int p = M;
while(p > 1 && v[p - 1] < v[p]) --p;
if(p == 1) {puts("Yes");return;}
for(int i = Q ; i >= 1 ; --i) {
if(a[i] == v[1]) reserve[1]++;
else {
if(reserve[pos[a[i]] - 1]) {
reserve[pos[a[i]] - 1]--;
reserve[pos[a[i]]]++;
}
}
}
int res = 0;
for(int i = p - 1 ; i <= M ; ++i) {
res += reserve[i];
}
if(res >= N) {puts("Yes");return;}
else {puts("No");return;}
} int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

【AtCoder】CODE FESTIVAL 2016 qual A的更多相关文章

  1. 【AtCoder】CODE FESTIVAL 2016 qual B

    CODE FESTIVAL 2016 qual B A - Signboard -- #include <bits/stdc++.h> #define fi first #define s ...

  2. 【AtCoder】CODE FESTIVAL 2016 qual C

    CODE FESTIVAL 2016 qual C A - CF -- #include <bits/stdc++.h> #define fi first #define se secon ...

  3. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  4. 【Atcoder】CODE FESTIVAL 2017 qual C D - Yet Another Palindrome Partitioning

    [题意]给定只含小写字母的字符串,要求分割成若干段使段内字母重组顺序后能得到回文串,求最少分割段数.n<=2*10^5 [算法]DP [题解]关键在于快速判断一个字符子串是否合法,容易发现合法仅 ...

  5. 【AtCoder】CODE FESTIVAL 2017 qual A

    A - Snuke's favorite YAKINIKU -- #include <bits/stdc++.h> #define fi first #define se second # ...

  6. 【AtCoder】CODE FESTIVAL 2017 qual B

    最近不知道为啥被安利了饥荒,但是不能再玩物丧志了,不能颓了 饥荒真好玩 A - XXFESTIVAL CCFESTIVAL #include <bits/stdc++.h> #define ...

  7. 【AtCoder】CODE FESTIVAL 2017 qual C

    A - Can you get AC? No #include <bits/stdc++.h> #define fi first #define se second #define pii ...

  8. 【AtCoder】CODE FESTIVAL 2017 Final

    A - AKIBA 模拟即可 代码 #include <bits/stdc++.h> #define fi first #define se second #define pii pair ...

  9. Atcoder CODE FESTIVAL 2016 qual C 的E题 Encyclopedia of Permutations

    题意: 对于一个长度为n的排列P,如果P在所有长度为n的排列中,按照字典序排列后,在第s位,则P的value为s 现在给出一个长度为n的排列P,P有一些位置确定了,另外一些位置为0,表示不确定. 现在 ...

随机推荐

  1. 洛谷P5369 [PKUSC2018]最大前缀和 [DP]

    传送门 思路 这么一道签到题竟然没切掉真是丢人呢-- 首先有一个\(O(3^n)\)的SB方法,记录\(dp_{S,T}\)表示已经填进去了\(S\),当前最大前缀和集合为\(T\),随便转移.太简单 ...

  2. 配置连接远程ip的Redis

    1.修改redis服务器的配置文件redis.windows.conf 注释绑定的主机地址 # bind 127.0.0.1 修改redis的守护进程为no,不启用 daemonize "n ...

  3. mongoose 安装及配置

    MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方>案.MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据 ...

  4. Flutter移动电商实战 --(33)列表页_子类和商品列表交互效果

    主要实现点击小类下面的列表跟着切换 获取右侧下面的列表信息,即要传递大类的id也要传递小类的,所以需要把左侧的大类的id也要Provide化 可以看下网站上的接口说明: https://jspang. ...

  5. test result

  6. Build Telemetry for Distributed Services之OpenTracing项目

    中文文档地址:https://wu-sheng.gitbooks.io/opentracing-io/content/pages/quick-start.html 中文github地址:https:/ ...

  7. Java NIO 学习笔记 读写结合补充

    小练习:nio读写文件,将fileread中的内容读取到filewrite中 try { //创建输入通道 FileInputStream fis = new FileInputStream(&quo ...

  8. 【ASP.NET Core学习】远程过程调用 - gRPC使用

    本文介绍在gRPC使用,将从下面几个方面介绍 什么是RPC 什么时候需要RPC 如何使用gRPC 什么是RPC RPC是Remote Procedure Call简称,翻译过来是远程过程调用.它是一个 ...

  9. JAVA 基础编程练习题44 【程序 44 偶数的素数和】

    44 [程序 44 偶数的素数和] 题目:一个偶数总能表示为两个素数之和. package cskaoyan; public class cskaoyan44 { @org.junit.Test pu ...

  10. clientdataset的使用

      clientdataset的使用(一) Delphi做为一个快速应用开发工具,深受程序员的喜爱.其强大的组件功能,让程序员能够轻松. 高效地完成常见的界面开发.数据库应用等功能.然而,帮助的相对缺 ...