COCI 2015、2016 1st round 题解(官方)
官方题解:





官方代码:
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 题解(官方)的更多相关文章
- COCI 2015/2016 Day 8 PROKLETNIK
PROKLETNIK 题目描述:给出\(n\)个数,定义一段连续的数为魔法串是该区间的左右端点值正好是区间的最小值与最大值(最小值可以在左也可以在右,最大值也一样).\(Q\)个询问,每次询问一个区间 ...
- 【COCI 2015/2016 #3】Nekameleoni
题目描述 “这好难啊,我有一个简单点的题,他们解决不了.” AKPAKP有一个长度为nn的线段,这个线段原来染有颜色,AKPAKP只认识kk种颜色.当然原来的颜色也包含在着kk种颜色之间. 可以进行m ...
- 2015,2016 Open Source Yearbook
https://opensource.com/yearbook/2015 The 2015 Open Source Yearbook is a community-contributed collec ...
- Dynamics XRM Tools 2015 2016
Download Link: Dynamics XRM Tools 2015/2016 Overview Dynamics XRM Tools brings you a quality range o ...
- 20145225《Java程序设计》 2015—2016年学期课程总结
20145225<Java程序设计> 2015—2016年学期课程总结 读书笔记链接汇总 1.2016年2月25日 <Java程序设计>课程准备之问卷调查 摘要: 一.你对自己 ...
- HeyWeGo小组《Java程序设计》 2015—2016年学期团队项目总结
HeyWeGo小组<Java程序设计> 2015—2016年学期团队项目总结 题目简介 一个简单的扫雷小游戏,在12*12的方格盘上,首先可以设定雷的个数,然后点击开始程序就会随机布雷,开 ...
- 2015 Astar Contest - Round 3 题解
1001 数长方形 题目大意 平面内有N条平行于坐标轴的线段,且不会在端点处相交 问共形成多少个矩形 算法思路 枚举4条线段的全部组合.分别作为矩形四条边.推断是否合法 时间复杂度: O(N4) 代码 ...
- 字符串(AC自动机):COCI 2015 round 5 divljak
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAy0AAANaCAIAAAALVTQoAAAgAElEQVR4nOy9X2hbx773PXfrQgQjDq
- @COCI 2016/2017 Round 3@ Meksikanac
目录 @description@ @solution@ @accepted code@ @details@ @description@ 在平面直角坐标系中,给定一个左下角为 (0, 0),右上角为 ( ...
随机推荐
- ASP.NET Core应用程序的参数配置及使用(转载)
本文结构 提前准备 参数配置方式 appsettings.json 环境变量 命令行参数 在控制器中使用配置参数 注入IConfiguration对象 注入IOptions对象 总结 应用程序的开发不 ...
- kafka controller脑裂(多个controller)问题
问题:情况一:创建topic成功,但是produce的时候,却报unknown partition的错误,但zk上却显示了每个partition的leader信息:情况二: 给某个topic增加分区, ...
- css 光标
<style> div{width:100;height:50;float:left;border:1px solid red;margin:1px;} </style> &l ...
- 【SQL】各取所需 | SQL JOIN连接查询各种用法总结
前面 在实际应用中,大多的查询都是需要多表连接查询的,但很多初学SQL的小伙伴总对各种JOIN有些迷糊.回想一下,初期很长一段时间,我常用的似乎也就是等值连接 WHERE 后面加等号,对各种JOIN也 ...
- 【WEB基础】HTML & CSS 基础入门(10)布局与定位
块级元素和行内元素 HTML里的元素可以分为块级元素和行内元素两大类:
- 2019 开创java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.开创等公司offer,岗位是Java后端开发,因为发展原因最终选择去了开创,入职一年时间了,也成为了面试官,之 ...
- springmvc处理json数据
springMVC提供了处理JSON格式请求/响应的HttpMessageConverter MappingJckson2HttpMessageConverter利用Jackson开源类包处理JSON ...
- 【转载】C#通过Contains方法判断DataTable中是否存在某个列名
在C#中的Datatable数据变量的操作过程中,有时候需要判断DataTable中是否存在某个列名,此时可以通过DataTable对象的Columns列对象集合属性下的Contains方法来进行判断 ...
- Workerman启动与停止相关命令
start.php为入口文件 一.启动 1.以debug(调试)方式启动 php start.php start 2.以daemon(守护进程)方式启动 php start.php start -d ...
- 环境搭建:Jupyter Notebook 密码设置
原文参考:关于jupyter notebook密码设置 原文博主: 一.windows下,打开命令行,重新生成一个jupyter配置文件 jupyter notebook --generate-con ...