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. 使用jsDelivr加速GitHub的静态资源
  2. AIR for IOS开发问题小结
  3. python引用文件的方法_[项目实践] python文件路径引用的
  4. docker部署nginx并且挂载文件夹和文件
  5. Linux awk编辑器及命令
  6. 聊起 BigTable,让你不再胆怯
  7. java高性能序列化_Java最佳实践–高性能序列化
  8. ajax 请求成功 再执行javascript,jquery中ajax请求后台数据成功后既不执行success也不执行error的完美解决方法...
  9. 日志能被截取吗 log4j_Java日志体系居然这么复杂?——架构篇
  10. 老板不在,你不得不做出越权的决定,咋办?(考试题系列)
  11. Quartus 与modelSim联合仿真常见错误以及系统任务$readmemb和$readmemh解释
  12. j2me模拟器qq2007_如何在J2ME中创建MIDlet
  13. 产品经理日常工作之流程图
  14. 搜索优化之四叉树算法(三)
  15. 深度学习基础----GAE和VGAE
  16. Java 打开资源管理器
  17. Java POI 导出 Excel 单元格 合并单元格 相邻的相同值 合并
  18. mysql创建数据库后出现Access denied for user 'root'@'%' to database ‘xxxx’
  19. 干货全拿走-用Excel制作小市值轮动价值投资选股器
  20. APT组织最喜欢的工具 Cobalt Strike (CS) 实战

热门文章

  1. 七夕关爱单身狗程序猿:4本书给你一个完整的脱单秘籍
  2. mysql 关闭in自动排序_为什么MySQL的in查询会自动排序
  3. python基本对象_python对象之对象基础1
  4. 我被认定为高层次人才了!
  5. 为什么switch里的case没有break不行
  6. 收到字节 Offer,月薪 45k,揭秘面试流程及考点
  7. 正式宣战关系型数据库市场,华为宣布开源一款人工智能数据库
  8. 【JEECG技术博文】JEECG 简单实例讲解权限控制
  9. jeewx-api.jar入门教程
  10. Spring安装与入门