官方题解:






官方代码:

Code-KARTE:

#include <cstdio>
#include <iostream>
#include <cstring> using namespace std; const int MAXB = 5;
const int MAXN = 20; bool bio[MAXB][MAXN]; int getColor(char chr) {
if (chr == 'P') return 0;
if (chr == 'K') return 1;
if (chr == 'H') return 2;
if (chr == 'T') return 3;
} int main(void) {
string s;
cin >> s;
for (int i = 0; i < s.size(); i += 3) {
int b = getColor(s[i]);
int x = (s[i + 1] - '0') * 10 + s[i + 2] - '0';
if (bio[b][x]) {
printf("GRESKA\n");
return 0;
}
bio[b][x] = true;
} for (int i = 0; i < 4; ++i) {
int cnt = 0;
for (int j = 1; j <= 13; ++j)
if (bio[i][j])
++cnt;
printf("%d ",13 - cnt);
}
printf("\n"); return 0;
}

Code-AKCIJA:

#include <cstdio>
#include <algorithm>
using namespace std; #define MAXN 100000
typedef long long llint; int C[MAXN]; bool cmp(int a, int b) {
return a > b;
} int main(void) {
int n; scanf ("%d", &n);
for (int i = 0; i < n; i++) {
scanf ("%d", &C[i]);
} sort(C, C+n, cmp); llint sol = 0;
for (int i = 0; i < n; i++) {
if (i % 3 == 2) {
continue;
}
sol += C[i];
} printf ("%lld\n", sol); return 0;
}

Code-BALONI:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set> using namespace std; const int MAXN = 1 << 20; int n; set <int> S[MAXN];
int find (int pos, int v) {
set<int>::iterator it = S[v].lower_bound(pos);
if (it == S[v].end()) return -1;
return *it;
} int v[MAXN]; int main (void){
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &v[i]);
S[v[i]].insert(i);
} int ans = 0;
for (int i = 0; i < n; ++i) {
if (S[v[i]].count(i) == 0) continue;
int pos = i;
++ans;
while (pos >= 0) {
S[v[pos]].erase(pos);
pos = find(pos, v[pos] - 1);
}
} printf("%d\n", ans); return 0;
}

Code-TOPOVI:

#include <cstdio>
#include <iostream>
#include <map> using namespace std; int n, k, q;
long long sol;
map <int, int> rcnt, ccnt;
map <int, int> rxor, cxor;
map <pair<int, int>, int> rook; void moveRook(int r, int c, int val) {
sol -= n - ccnt[rxor[r]];
sol -= n - rcnt[cxor[c]];
if (rxor[r] != cxor[c])
sol += 1; --rcnt[rxor[r]];
rxor[r] ^= val;
++rcnt[rxor[r]]; --ccnt[cxor[c]];
cxor[c] ^= val;
++ccnt[cxor[c]]; sol += n - ccnt[rxor[r]];
sol += n - rcnt[cxor[c]];
if (rxor[r] != cxor[c])
sol -= 1; rook[make_pair(r, c)] ^= val;
} void init(void) {
scanf("%d %d %d",&n,&k,&q);
rcnt[0] = ccnt[0] = n;
for (int i = 0; i < k; ++i) {
int r, c, val;
scanf("%d %d %d",&r,&c,&val);
--r;
--c;
moveRook(r, c, val);
}
} void solve(void) {
while (q-- > 0) {
int r1, c1, r2, c2;
scanf("%d %d %d %d",&r1,&c1,&r2,&c2);
--r1; --c1;
--r2; --c2;
int rookValue = rook[make_pair(r1, c1)];
moveRook(r1, c1, rookValue);
moveRook(r2, c2, rookValue);
printf("%lld\n",sol);
}
} int main(void) {
init();
solve();
return 0;
}

Code-RELATIVNOST:

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm> using namespace std; typedef unsigned int uint; const int MAXN = 100005;
const int MAXC = 21;
const int mod = 10007; int n, c, q;
int a[MAXN];
int b[MAXN];
int T[2 * MAXN][MAXC]; void update(int x) {
for (int i = 0; i <= c; ++i) T[x][i] = 0; for (int i = 0; i <= c; ++i)
for (int j = 0; j <= c; ++j)
T[x][min(i + j, c)] += (T[x * 2][i] * T[x * 2 + 1][j]) % mod; for (int i = 0; i <= c; ++i) T[x][i] %= mod;
} void change(int x) {
x += n;
memset(T[x], 0, sizeof T[x]);
T[x][1] = a[x - n] % mod;
T[x][0] = b[x - n] % mod; for (x /= 2; x > 0; x /= 2) update(x);
} int main(void) {
scanf("%d%d", &n, &c);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
for (int i = 0; i < n; ++i) {
T[i + n][0] = b[i] % mod;
T[i + n][1] = a[i] % mod;
} for (int i = n-1; i >= 1; --i)
update(i); scanf("%d", &q);
for (int i = 0; i < q; ++i) {
int p;
scanf("%d", &p); --p;
scanf("%d%d", &a[p], &b[p]);
change(p);
printf("%d\n", T[1][c]);
} return 0;
}

Code-UZASTOPNI:

#include <cstdio>
#include <iostream>
#include <cstring>
#include <bitset>
#include <vector> #define lo first
#define hi second using namespace std; using interval = pair<int, int>; const int MAXN = 10010;
const int MAXK = 110; int n, v[MAXN];
vector<int> e[MAXN]; vector<interval> s[MAXN];
vector<int> q[MAXK];
bitset<MAXK> flag[MAXN][MAXK]; void dfs(int x) {
for (auto y : e[x])
dfs(y); for (int i = 0; i < MAXK; ++i)
q[i].clear();
for (auto y : e[x]) {
for (auto it : s[y])
q[it.lo].push_back(it.hi);
} for (int lo = MAXK - 1; lo >= 1; --lo) {
if (lo == v[x]) {
flag[x][lo] |= flag[x][lo + 1];
flag[x][lo].set(lo);
} else {
for (auto hi : q[lo]) {
if (hi < v[x] || lo > v[x]) {
flag[x][lo] |= flag[x][hi + 1];
flag[x][lo].set(hi);
}
}
} for (int hi = MAXK - 1; hi >= lo; --hi)
if (flag[x][lo].test(hi) && v[x] >= lo && v[x] <= hi) {
s[x].emplace_back(lo, hi);
}
}
} void init(void) {
scanf("%d",&n);
for (int i = 0; i < n; ++i)
scanf("%d",&v[i]);
for (int i = 0; i < n - 1; ++i) {
int a, b;
scanf("%d %d",&a,&b);
--a;
--b;
e[a].push_back(b);
}
} void solve(void) {
dfs(0);
printf("%d\n",s[0].size());
} int main(void) {
init();
solve();
return 0;
}

COCI 2015、2016 1st round 题解(官方)的更多相关文章

  1. COCI 2015/2016 Day 8 PROKLETNIK

    PROKLETNIK 题目描述:给出\(n\)个数,定义一段连续的数为魔法串是该区间的左右端点值正好是区间的最小值与最大值(最小值可以在左也可以在右,最大值也一样).\(Q\)个询问,每次询问一个区间 ...

  2. 【COCI 2015/2016 #3】Nekameleoni

    题目描述 “这好难啊,我有一个简单点的题,他们解决不了.” AKPAKP有一个长度为nn的线段,这个线段原来染有颜色,AKPAKP只认识kk种颜色.当然原来的颜色也包含在着kk种颜色之间. 可以进行m ...

  3. 2015,2016 Open Source Yearbook

    https://opensource.com/yearbook/2015 The 2015 Open Source Yearbook is a community-contributed collec ...

  4. Dynamics XRM Tools 2015 2016

    Download Link: Dynamics XRM Tools 2015/2016 Overview Dynamics XRM Tools brings you a quality range o ...

  5. 20145225《Java程序设计》 2015—2016年学期课程总结

    20145225<Java程序设计> 2015—2016年学期课程总结 读书笔记链接汇总 1.2016年2月25日 <Java程序设计>课程准备之问卷调查 摘要: 一.你对自己 ...

  6. HeyWeGo小组《Java程序设计》 2015—2016年学期团队项目总结

    HeyWeGo小组<Java程序设计> 2015—2016年学期团队项目总结 题目简介 一个简单的扫雷小游戏,在12*12的方格盘上,首先可以设定雷的个数,然后点击开始程序就会随机布雷,开 ...

  7. 2015 Astar Contest - Round 3 题解

    1001 数长方形 题目大意 平面内有N条平行于坐标轴的线段,且不会在端点处相交 问共形成多少个矩形 算法思路 枚举4条线段的全部组合.分别作为矩形四条边.推断是否合法 时间复杂度: O(N4) 代码 ...

  8. 字符串(AC自动机):COCI 2015 round 5 divljak

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAy0AAANaCAIAAAALVTQoAAAgAElEQVR4nOy9X2hbx773PXfrQgQjDq

  9. @COCI 2016/2017 Round 3@ Meksikanac

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 在平面直角坐标系中,给定一个左下角为 (0, 0),右上角为 ( ...

随机推荐

  1. asp.net core mvc 集成miniprofiler

    原文:asp.net core mvc 集成miniprofiler asp.net core mvc 集成miniprofiler 一.环境介绍 二.监控asp.net 页面 三.监控执行的sql语 ...

  2. c++打印实心菱形,空心三角形,十字星,空心正方形,实心平行四边形

    今天翻资料的时候,无意间发现了一个文件,是刚接触编程的时候用c++写的一段程序,我称之为"图形打印机",想着把所有图形都打印出来,后来发现其实每种图形的代码都是一个思路,就不想做重 ...

  3. 接口例_龟车赛跑_Java

    此例演示java中接口的一般用法. 屋子里有一群程序员,每个人在写着自己的类,共同构建一个世界. 项目经理突然出现:“打扰大家一下,公司决定举办一个竞速比赛,你们写的类都可以参加.为了比赛的顺利进行, ...

  4. Smack Extensions用户手册

    Smack Extensions用户手册 XMPP协议包括基本协议和许多可选扩展,通常记录为“XEP”.Smack为核心XMPP协议提供了org.jivesoftware.smack包,为许多协议扩展 ...

  5. Prime Path POJ-3126

    The ministers of the cabinet were quite upset by the message from the Chief of Security stating that ...

  6. Java深入学习(2):并发队列

    并发队列: 在并发队列中,JDK有两套实现: ConcurrentLinkedQueue:非阻塞式队列 BlockingQueue:阻塞式队列 阻塞式队列非阻塞式队列的区别: 阻塞式队列入列操作的时候 ...

  7. AI面试-算法结构基础

    其实目前国内几乎只要是技术岗,面试中都100%会问算法和数据结构. 这两者能快速体现候选人真实的水平,比如代码量,代码的质量,性能,思维是否有逻辑,是否灵活. 算法结果概述 1.前言 1.应用范围:机 ...

  8. YUV视频格式详解(翻译自微软文档)

    原文: https://docs.microsoft.com/en-us/previous-versions/aa904813(v=vs.80) YUV视频格式详解(翻译自微软文档)https://b ...

  9. 转摘jemeter学习-连接数据库之jdbc请求

    JMETER连接数据库 mysql下载地址:https://dev.mysql.com/downloads/connector/j/ mysql连接器根据语言选择/J,用的是Mac,选择下载.tar. ...

  10. css 带换行的垂直居中

    span{ display:flex; justify-content:left; align-items:center; height:100%; width:100%; }