首頁  >  文章  >  web前端  >  Codeforces Round #280 (Div. 2 A,B,C,D,E)_html/css_WEB-ITnose

Codeforces Round #280 (Div. 2 A,B,C,D,E)_html/css_WEB-ITnose

WBOY
WBOY原創
2016-06-24 11:52:59849瀏覽

改了时区之后打cf更辛苦了啊。。。昨天没做,今天补了一下啊。

A. Vanya and Cubes

每次加的数规律性很明显就是:(i+1)*i/2。暴力枚举i就可以得到答案。

#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define eps 1e-8#define M 1000100#define LL long long//#define LL long long#define INF 0x3f3f3f#define PI 3.1415926535898#define mod 1000000007#define rson mid+1, r, rt= n) break;        }        if(sum > n) ans--;        cout  <br> B - Vanya and Lanterns  <br>  <p></p>  <p>按照顺序排序,之后求出间距最小的来,注意判断起点与终点,因为他们的距离不用/2。</p>  <p></p>  <pre name="code" class="sycode">#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define eps 1e-8#define M 1000100#define LL long long//#define LL long long#define INF 0x3f3f3f#define PI 3.1415926535898#define mod 1000000007#define rson mid+1, r, rt  <br> C - Vanya and Exams  <br>  <p></p>  <p>C看懂题目就很简单了啊,就是排序之后的一个贪心。</p>  <p></p>  <pre name="code" class="sycode">#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define eps 1e-8#define M 1000100#define LL long long//#define LL long long#define INF 0x3f3f3f#define PI 3.1415926535898#define mod 1000000007#define rson mid+1, r, rt sp)            {                sum += sp;                xans += f[i].b*sp;            }            else            {                xans += p*f[i].b;                sum += p;                break;            }        }        cout  <br> D - Vanya and Computer Game  <br>  <p></p>  <p>给你一个x,一个y。让你判断在n次以内x,y谁先完成任务,其实就是判断谁的整数倍先到给的nx,二分枚举,如果是x,y的公倍数输出both,如果是y的倍数输出:Vanya,如果是x的倍数输出:Vova.</p>  <p></p>  <p class="sycode">   </p>
<p class="sycode">    D. Vanya and Computer Game   </p>   <p class="sycode">    </p>
<p class="sycode">     time limit per test    </p> 2 seconds      <p class="sycode">    </p>
<p class="sycode">     memory limit per test    </p> 256 megabytes      <p class="sycode">    </p>
<p class="sycode">     input    </p> standard input      <p class="sycode">    </p>
<p class="sycode">     output    </p> standard output       <p class="sycode">   </p>
<p> Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to raise the weapon is 1?/?x seconds for the first character and 1?/?y seconds for the second one). The i-th monster dies after he receives ai hits.</p>   <p> Vanya and Vova wonder who makes the last hit on each monster. If Vanya and Vova make the last hit at the same time, we assume that both of them have made the last hit.</p>    <p class="sycode">   </p>
<p class="sycode">    Input   </p>   <p> The first line contains three integers n,x,y (1?≤?n?≤?105, 1?≤?x,?y?≤?106) ? the number of monsters, the frequency of Vanya's and Vova's attack, correspondingly.</p>   <p> Next n lines contain integers ai (1?≤?ai?≤?109) ? the number of hits needed do destroy the i-th monster.</p>    <p class="sycode">   </p>
<p class="sycode">    Output   </p>   <p> Print n lines. In the i-th line print word "Vanya", if the last hit on the i-th monster was performed by Vanya, "Vova", if Vova performed the last hit, or "Both", if both boys performed it at the same time.</p>    <p class="sycode">   </p>
<p class="sycode">    Sample test(s)   </p>   <p class="sycode">    </p>
<p class="sycode">     </p>
<p class="sycode">      input     </p>     <pre style="代码" class="precsshei">4 3 21234

output

VanyaVovaVanyaBoth

input

2 1 112

output

BothBoth

Note

In the first sample Vanya makes the first hit at time 1?/?3, Vova makes the second hit at time 1?/?2, Vanya makes the third hit at time 2?/?3, and both boys make the fourth and fifth hit simultaneously at the time 1.

In the second sample Vanya and Vova make the first and second hit simultaneously at time 1.

#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <time.h>#include <map>#include <set>#define eps 1e-8#define M 1000100#define LL long long//#define LL long long#define INF 0x3f3f3f#define PI 3.1415926535898#define mod 1000const int maxn = 200010;using namespace std;const LL R = 1e15;int main(){    LL n, x, y;    while(~scanf("%I64d %I64d %I64d", &n, &x, &y))    {        LL nx;        for(int i = 0; i >1;                if(mid/x+mid/y   <br> E - Vanya and Field  <br>  <p></p>  <p>这个题目挺好的,其实他是有规律的:</p>  <p> 题目的关键条件是这个  </p>  <p> 首先想个问题,先是一维的情况下,假设只有一行的格子,长度为x,每次能移动的距离为dx,而且gcd(x,dx)=1,这样手动模拟一下,可以发现规律,从某个点出发直到回到这个点上,步数均为x次,而且每次落下的点都是不重复的,也即这x次的位置覆盖了整条方格上的每一个方格。</p>  <p> 那现在二维的情况下,gcd(n,dx) = gcd(n,dy) = 1,也就是从某一行和某一列的交点出发,要重新回到这个交点,就要经过n步而且这n步覆盖了每一行每一列。每个循环必须每个x走一次以及每个y走一次,n个格子属于一组循环里面的,总共有n*n个格子,所以有n组循环。一组循环内的格子是等价的。同一行内的n个格子均来自不同的n组。</p>  <p> </p>  <p> 现在考虑一组特殊的循环,这组循环从(0,0)开始出发</p>  <p> 走了第一步以后就到 (dx%n, dy%n) </p>  <p> 第二步到 (2*dx%n, 2*dy%n)</p>  <p> 第k步到 (k*dx%n, k*dy%n)</p>  <p> 用一个对应关系存储,从(0,0)出发的,经过了k步以后,会到达位置(x[k] , y[k])。</p>  <p>  </p>  <p> 然后考虑普遍的情况了,每组循环都比如经过(0, y0)这个点</p>  <p> 从这个点出发的第一步 (dx%n, (y0+dy)%n) </p>  <p> 第k步到 (dx%n, (y0+dy)%n), 也即(x[k], (y0+y[k])%n)</p>  <p>  </p>  <p> 那么现在给你某个坐标(x,y),要怎么算出他属于哪一组循环的呢</p>  <p> 根据等式x[k]==x,可以求出对应的k的值</p>  <p> 那就能求出对应的y[k]了,然后y0+y[k]==y →  y0=y-y[k]</p>  <p> 这样就知道这个(x,y) 是属于 (0,y0)这一组的了</p>  <p>  </p>  <p> 那么算法大概是这样:</p>  <p> 预处理出x[k],y[k],时间复杂度o(n)</p>  <p> 遍历每一个apple的坐标(x,y),求出对应的坐标(0,y0),然后cnt[y0]++,复杂度o(m)</p>  <p> 找出值最大的cnt[y],答案就是(0,y)了。 总复杂度o(n+m)</p>  <br>  <p> 摘自:http://www.cnblogs.com/someblue/p/4136436.html</p>  <p> </p>  <p class="sycode">   </p>
<p class="sycode">    E. Vanya and Field   </p>   <p class="sycode">    </p>
<p class="sycode">     time limit per test    </p> 2 seconds      <p class="sycode">    </p>
<p class="sycode">     memory limit per test    </p> 256 megabytes      <p class="sycode">    </p>
<p class="sycode">     input    </p> standard input      <p class="sycode">    </p>
<p class="sycode">     output    </p> standard output       <p class="sycode">   </p>
<p> Vanya decided to walk in the field of size n?×?n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates(xi,?yi). Vanya moves towards vector (dx,?dy). That means that if Vanya is now at the cell (x,?y), then in a second he will be at cell . The following condition is satisfied for the vector: , where  is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.</p>   <p> Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.</p>    <p class="sycode">   </p>
<p class="sycode">    Input   </p>   <p> The first line contains integers n,?m,?dx,?dy(1?≤?n?≤?106, 1?≤?m?≤?105, 1?≤?dx,?dy?≤?n) ? the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi,?yi (0?≤?xi,?yi?≤?n?-?1) ? the coordinates of apples. One cell may contain multiple apple trees.</p>    <p class="sycode">   </p>
<p class="sycode">    Output   </p>   <p> Print two space-separated numbers ? the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.</p>    <p class="sycode">   </p>
<p class="sycode">    Sample test(s)   </p>   <p class="sycode">    </p>
<p class="sycode">     </p>
<p class="sycode">      input     </p>     <pre style="代码" class="precsshei">5 5 2 30 01 21 32 43 1

output

1 3

input

2 3 1 10 00 11 1

output

0 0

Note

In the first sample Vanya's path will look like: (1,?3)?-?(3,?1)?-?(0,?4)?-?(2,?2)?-?(4,?0)?-?(1,?3)

In the second sample: (0,?0)?-?(1,?1)?-?(0,?0)

#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <math.h>#include <time.h>#include <stack>#include <map>#include <set>#define eps 1e-8///#define LL long long#define LL __int64#define INF 0x3f3f3f#define PI acos(-1)#define mod 1000000007using namespace std;const int maxn = 10000010;int vis[maxn];int num[maxn];struct node{    int x, y;    int k;}f[maxn];int main(){    int n, m, dx, dy;    while(~scanf("%d %d %d %d",&n, &m, &dx, &dy))    {        f[0].x = 0;        f[0].y = 0;        f[0].k = 0;        vis[0] = 0;        for(int i = 1; i   <br>  <br>  <p></p> </set></map></stack></time.h></math.h></cmath></queue></string></stdio.h></iomanip></string.h></stdlib.h></iostream></algorithm>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn