日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Bear in the Field(CF-385E)

發布時間:2025/3/17 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Bear in the Field(CF-385E) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 伊人久久艹 | 亚洲AV永久无码国产精品国产 | 男人把女人捅爽 | 在线一区二区三区四区五区 | 国产特级淫片免费看 | 中文字幕免费高清在线 | 国产一区二区免费在线观看 | 久久久一区二区三区四区 | 二区视频在线 | 福利社区一区二区 | 国产亚洲精品久久久久久久久动漫 | 狠狠操2019 | 18深夜在线观看免费视频 | 亚洲国产区 | 浮力影院草草 | 丁香婷婷深情五月亚洲 | 超黄av| 男人午夜网站 | 新婚之夜玷污岳丰满少妇在线观看 | 99热这里只有精品4 精品国产黄色 | 日韩一区二区三区不卡视频 | wwww在线观看| 羞羞网站在线观看 | 精品人妻一区二区三区蜜桃 | 亚洲一级二级三级 | 日本特黄特黄刺激大片 | 久久婷婷成人综合色 | 黄色三级在线观看 | 动漫av网站免费观看 | 日韩精品免费一区二区三区竹菊 | a黄色大片 | 亚洲视频999 | 91成人在线观看喷潮 | 日批网站在线观看 | 麻豆亚洲精品 | 蜜桃臀aⅴ精品一区二区三区 | 亚洲一区二区电影 | xx视频在线| 国产露出视频 | 亚洲精品久久久久久久蜜桃臀 | 根深蒂固在线观看 | 国产精品污www一区二区三区 | 黄色片视频免费看 | 亚洲免费观看高清完整版在线 | 99国产精 | 高清国产一区二区三区四区五区 | 成人av一区二区三区 | 中文字幕人妻一区二区三区视频 | 五月网婷婷 | 动漫精品一区一码二码三码四码 | jizz俄罗斯 | 一级黄色片大全 | 亚洲福利小视频 | 国产一区自拍视频 | 国产精品精品软件视频 | 国精产品一区一区三区 | 五月天亚洲色图 | xxxx日本少妇 | 日本午夜在线 | 国产片久久 | 亚洲一级黄色片 | 中文字幕无码精品亚洲35 | 两根大肉大捧一进一出好爽视频 | 精品一区二区在线观看视频 | 天天爽天天做 | 日韩人妻一区二区三区蜜桃视频 | 精品人妻aV中文字幕乱码色欲 | 欧美精品一级二级三级 | 国模无码国产精品视频 | 欧美日韩卡一卡二 | 成人自拍视频在线观看 | h片观看| 国产主播在线看 | 在线成人播放 | 麻豆回家视频区一区二 | 亚洲专区在线 | 老湿影院av| 国产一区二区三区免费观看 | 亚洲欧美精品一区二区三区 | 五月av在线 | 涩涩网站免费 | 夜夜高潮夜夜爽国产伦精品 | 永久免费精品影视网站 | 天堂√| 成人av网站在线观看 | 五月婷婷六月丁香综合 | 欧美三级手机在线观看 | 天堂中文字幕av | 国产碰碰 | 九九国产精品视频 | 日韩成人av一区二区 | 日韩成人福利视频 | 精品国产精品 | 一级黄色美女 | 亚洲AV无码久久精品色三人行 | 日本精品一区二区视频 | 干干操操 | 免费99精品国产自在在线 | 色妞视频|