Problem Description

Our bear's forest has a checkered field. The checkered field is an n × n table, the rows are numbered from 1 to n from top to bottom, the columns are numbered from 1 to n from left to right. Let's denote a cell of the field on the intersection of row x and column y by record (x, y). Each cell of the field contains growing raspberry, at that, the cell (x, y) of the field contains x + y raspberry bushes.

The bear came out to walk across the field. At the beginning of the walk his speed is (dx, dy). Then the bear spends exactly t seconds on the field. Each second the following takes place:

Let's suppose that at the current moment the bear is in cell (x, y).
First the bear eats the raspberry from all the bushes he has in the current cell. After the bear eats the raspberry from k bushes, he increases each component of his speed by k. In other words, if before eating the k bushes of raspberry his speed was (dx, dy), then after eating the berry his speed equals (dx + k, dy + k).
Let's denote the current speed of the bear (dx, dy) (it was increased after the previous step). Then the bear moves from cell (x, y) to cell (((x + dx - 1) mod n) + 1, ((y + dy - 1) mod n) + 1).
Then one additional raspberry bush grows in each cell of the field.
You task is to predict the bear's actions. Find the cell he ends up in if he starts from cell (sx, sy). Assume that each bush has infinitely much raspberry and the bear will never eat all of it.

Input

The first line of the input contains six space-separated integers: n, sx, sy, dx, dy, t (1 ≤ n ≤ 109; 1 ≤ sx, sy ≤ n; - 100 ≤ dx, dy ≤ 100; 0 ≤ t ≤ 1018).

Output

Print two integers — the coordinates of the cell the bear will end up in after t seconds.

Example

Input

5 1 2 0 1 2

output

3 1

Input

1 1 1 -1 -1 2

Input

1 1

题意:给出 n、x、y、dx、dy、t 代表有一个 n*n 的图,每个点上行有 x+y 个草莓,现在从 (sx,sy) 出发,速度为 (dx,dy),其中对于每个点,每过一秒就会多 1 个草莓,速度增加当前位置上的草莓数,问 t 秒后的位置

思路:

根据题意,有:

其中,

对于时间 t,则有:

由于存在取模运算,%n 时只会产生 0~n-1 的数,因此将位置坐标都向上、向左平移一下,这样坐标范围变成 0~n-1,但这样会导致速度增加量减少了 2,因此需要加上 2

于是,有:

代入 

有:

于是,可以构造矩阵:

化简得:

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define PI acos(-1.0)
#define E 1e-9
#define INF 0x3f3f3f3f
#define LL long long
const int MOD=1000000007;
const int N=10+5;
//const int dx[]= {-1,1,0,0};
//const int dy[]= {0,0,-1,1};
using namespace std;
struct Matrix{LL s[N][N];
};
Matrix e;//单位矩阵E
Matrix x;//构造矩阵
LL mod;
Matrix mul(Matrix A,Matrix B,LL n){//矩阵乘法,n代表A、B两个矩阵是n阶方阵Matrix temp;//临时矩阵,存放A*B结果for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)temp.s[i][j]=0;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)for(int k=1;k<=n;k++)temp.s[i][j]=((temp.s[i][j]+A.s[i][k]*B.s[k][j])%mod+mod)%mod;return temp;
}
Matrix quickPower(Matrix a,LL b,LL n){//矩阵快速幂,求矩阵n阶矩阵的b次幂Matrix ans=e;while(b){if(b&1)ans=mul(ans,a,n);//ans=e*aa=mul(a,a,n);//a=a*ab>>=1;}return ans;
}
LL n,sx,sy,dx,dy,t;
LL y[N];
void init(){for(int i=1;i<=6;i++)//主对角线为1e.s[i][i]=1;x.s[1][1]=2;x.s[1][2]=1;x.s[1][3]=1;x.s[1][4]=0;x.s[1][5]=1;x.s[1][6]=2;x.s[2][1]=1;x.s[2][2]=2;x.s[2][3]=0;x.s[2][4]=1;x.s[2][5]=1;x.s[2][6]=2;x.s[3][1]=1;x.s[3][2]=1;x.s[3][3]=1;x.s[3][4]=0;x.s[3][5]=1;x.s[3][6]=2;x.s[4][1]=1;x.s[4][2]=1;x.s[4][3]=0;x.s[4][4]=1;x.s[4][5]=1;x.s[4][6]=2;x.s[5][1]=0;x.s[5][2]=0;x.s[5][3]=0;x.s[5][4]=0;x.s[5][5]=1;x.s[5][6]=1;x.s[6][1]=0;x.s[6][2]=0;x.s[6][3]=0;x.s[6][4]=0;x.s[6][5]=0;x.s[6][6]=1;y[1]=sx-1;y[2]=sy-1;y[3]=dx;y[4]=dy;y[5]=0;y[6]=1;
}
int main(){while(scanf("%lld%lld%lld%lld%lld%lld",&n,&sx,&sy,&dx,&dy,&t)!=EOF){if(t==0)printf("%lld %lld",sx,sy);else{mod=n;init();Matrix res=quickPower(x,t,6);LL ex=0,ey=0;for(int i=1;i<=6;i++)ex=((ex+res.s[1][i]*y[i])%mod+mod)%mod;for(int i=1;i<=6;i++)ey=((ey+res.s[2][i]*y[i])%mod+mod)%mod;printf("%lld %lld\n",ex+1,ey+1);}}return 0;
}

Bear in the Field(CF-385E)相关推荐

  1. 【解题报告】随便练练二(CF 2300)

    [解题报告]随便练练二(CF 2300) A:Antimatter | CF383D 题意 思路 :DP 代码 B:Physical Education Lessons | CF915E 题意 思路一 ...

  2. codeforces679C Bear and Square Grid(dfs优化)

    题意: 给你n*n的矩阵(n<=500),矩阵内有x和.,然后给你一个k 你可以把一个k*k的矩阵内全部变成. 问你最多有多少个.可以联通 思路: n^2枚举炸的位置,先预处理联通块和区间.的和 ...

  3. Commentator problem(CF 2)

    题目链接 题目大意: 给定三个圆,询问是否存在点满足该点与三个圆夹角均相等,若存在多组解返回夹角最大值. 圆外一点到两圆夹角均相等: 即 sina = sinb = r1 / d1 = r2 / d2 ...

  4. Codeforces A - Bear and Prime 100(交互题)

    A - Bear and Prime 100 思路:任何一个合数都可以写成2个以上质数的乘积.在2-100中,除了4,9,25,49外都可以写成两个以上不同质数的乘积. 所以打一个质数加这四个数的表: ...

  5. D. Make a Power of Two(cf#739DIV3)

    D. Make a Power of Two 链接: link. 题意: 找出将数字转换为 2 的任意幂的最小移动次数. 题解: 先将2的xxx次幂的结果以字符串形式保存,输入字符串nnn后,因为存在 ...

  6. Web of Lies(CF 1548A)

    这是今天在打个人赛时碰见的一道题,是一道半图论半思维的题. Web of Lies 题目大意不难理解,在这里只需要注意一些细节.在加边时,只有当cnt[min]的值为1时答案才应该减1,而不是当cnt ...

  7. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

  8. 重构改善既有代码设计--重构手法11:Move Field (搬移字段)

    你的程序中,某个字段被其所驻类之外的另一个类更多的用到.在目标类建立一个新字段,修改源字段的所有用户,令它们改用新字段.        动机:在类之间移动状态和行为,是重构过程中必不可少的措施.随着系 ...

  9. 【解题报告】博弈专场 (CF 2000~2200)前五题

    [解题报告]博弈专场 (CF 2000+)前五题 A:Fox and Card Game | CF388C 题意 思路 代码 B:Berzerk | CF786A 题意 思路 代码 C:Ithea P ...

最新文章

  1. Nature Cancer | 发现非肿瘤药物的抗癌潜力
  2. Unity 2D游戏开发教程之使用脚本实现游戏逻辑
  3. Matlab-基于短时神经网络的声音分类
  4. MySQL 5.7的新特性(新功能)
  5. ImportError: No module named model_libs
  6. java状态模式和策略模式_Java状态和策略设计模式之间的差异
  7. 即将改变软件开发的5个Java9新特性
  8. 模糊PID控制在自动光电整纬装置中的应用
  9. 微信应用开发简单示例,学生自助报道系统
  10. 计算机万维考试题,计算机培训 万维考试系统选择题题库(含参考答案).pdf
  11. Linux之DNS篇
  12. C语言中的数组(4)---二维数组的定义
  13. html只显示一次,javascript – 只显示div一次
  14. springMvc中的校验框架@valid和@validated
  15. AutoJs学习-QQ自动点赞及打卡
  16. C++ 小游戏之推箱子
  17. 人工智能实战2019 第二次作业 焦宇恒
  18. WiFi_Display_Spec
  19. 带密码的php文件管理器,PHP文件管理器Tiny File Manager账号密码修改方法
  20. 如人饮水,冷暖自知。

热门文章

  1. “年薪25万只是白菜价”已成过去式,AI 岗位年薪下降8.9%!
  2. 最新!2001-2021武书连中国大学排行榜Top 20
  3. 豆瓣7.6,这部被低估的科幻片告诉你,通过图灵测试的AI有多可怕!
  4. PaaS、DevOps、OpenShift与业务中台的实现
  5. 20 行 Python 代码说清量子霸权!
  6. 隔离式BUCK之参数计算
  7. STM32之SPI从机例程
  8. 看完源码记不住,是我记性太差了吗?
  9. 漫话:为什么键盘以QWER排列,而不是ABCD?
  10. SQL查询环比增长 前后行数据对比操作