[Codeforces 863C]1-2-3
Description
Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice".
So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3.
Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game.
Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game.
Input
The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3).
Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3).
Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3).
Output
Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games.
Sample Input
10 2 1
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
2 2 2
Sample Output
1 9
题解
显然序列是循环的,我们找出循环节,并单独考虑循环节之前的和之后的。
//It is made by Awson on 2017.9.30
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))
using namespace std;
void read(int &x) {
char ch; bool flag = ;
for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || ); ch = getchar());
for (x = ; isdigit(ch); x = (x<<)+(x<<)+ch-, ch = getchar());
x *= -*flag;
} int A[][], B[][];
LL k, ans;
int ra[], rb[], top;
int vis[][];
int a, b, l, r;
LL ans1, ans2, cnt1, cnt2; void vs(int a, int b, LL &x, LL &y) {
if (a == b) return;
if (a == ) {
if (b == ) y++;
else x++;
return;
}
if (a == ) {
if (b == ) y++;
else x++;
return;
}
if (a == ) {
if (b == ) y++;
else x++;
return;
}
}
void work() {
scanf("%I64d", &k);
read(a), read(b);
for (int i = ; i <= ; i++)
for (int j = ; j <= ; j++)
read(A[i][j]);
for (int i = ; i <= ; i++)
for (int j = ; j <= ; j++)
read(B[i][j]);
ra[++top] = a, rb[top] = b;
vis[a][b] = top;
while (true) {
a = A[ra[top]][rb[top]];
b = B[ra[top]][rb[top]];
if (vis[a][b]) {
l = vis[a][b], r = top;
break;
}
ra[++top] = a, rb[top] = b;
vis[a][b] = top;
}
if ((LL)l- > k) l = k+;
k -= l-;
for (int i = ; i < l; i++)
vs(ra[i], rb[i], ans1, ans2);
if (k) {
LL lenth = r-l+;
for (int i = l; i <= r; i++)
vs(ra[i], rb[i], cnt1, cnt2);
ans1 += k/lenth*cnt1;
ans2 += k/lenth*cnt2;
k %= lenth;
for (int i = ; i < k; i++)
vs(ra[l+i], rb[l+i], ans1, ans2);
}
printf("%I64d %I64d\n", ans1, ans2);
}
int main() {
work();
return ;
}
[Codeforces 863C]1-2-3的更多相关文章
- 暑期训练 CF套题
CodeForces 327A 题意:有n个数,都是0或1,然后必须执行一次操作,翻转一个区间,里面的数0变1,1变0,求最多1的数量 思路:最开始我写的最大字段和,后面好像写搓了,然后我又改成暴力, ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- 使用.NET开发AutoCAD——设计师不做画图匠(一)
(一)前言--如何避免加班那些事 我是谁?我是一名工程设计师,有点"不务正业",在工作之余长期从事软件开发工作,开发了公路铁路行业广泛应用的设计软件.说正题之前,聊聊加班那些事.话 ...
- Leetcode 27——Remove Element
Given an array and a value, remove all instances of that value in-place and return the new length. D ...
- [福大软工] W班 软件产品案例分析
作业要求 https://edu.cnblogs.com/campus/fzu/FZUSoftwareEngineering1715W/homework/1300 评分细则 第一部分 调研,评测 (3 ...
- 201621123060《JAVA程序设计》第九周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 2. 书面作业 本次作业题集集合 1. List中指定元素的删除(题集题目) 1.1 实验总结.并回答:列举至 ...
- Alpha阶段小结
1 团队的源码仓库地址 https://github.com/WHUSE2017/MyGod 2 Alpha过程回顾 2.1 团队项目预期 有一个可视化的安卓APP,实现二手交易基本功能.预期的典型用 ...
- 咬碎STL空间配置器
STL空间配置器 一.开场白: 给我的感觉就是,了解是空间配置器的功能,是那么的明了:在看原理,我还是很开心:接下来是360度大转变: 那么长的变量或者函数命名.那么多的宏.不爽,不过,遇上我这种二货 ...
- 2017 国庆湖南 Day5
期望得分:76+80+30=186 实际得分:72+10+0=82 先看第一问: 本题不是求方案数,所以我们不关心 选的数是什么以及的选的顺序 只关心选了某个数后,对当前gcd的影响 预处理 cnt[ ...
- Python之旅.第三章.函数3.30
一.迭代器 1.什么是迭代?:迭代是一个重复的过程,并且每次重复都是基于上一次的结果而来2.要想了解迭代器到底是什么?必须先了解一个概念,即什么是可迭代的对象?可迭代的对象:在python中,但凡内置 ...
- Hangfire使用ApplicationInsigts监控
起因 我司目前使用清真的ApplicationInsights(以下简称Ai)来做程序级监控.(Ai相关文档: https://azure.microsoft.com/zh-cn/services/a ...
- python全栈开发-re模块(正则表达式)应用(字符串的处理)
一.概述 就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,要讲他的具体用法要讲一本书!它内嵌在Python中,并通过 re 模块实现.你可以为想要匹配的相应字符串集指定规则:该 ...