Codeforces #430 dv.2 842A ,842B

来源:互联网 发布:交易训练软件 编辑:程序博客网 时间:2024/06/06 19:53



0 0   两道题,

A. Kirill And The Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.

For each two integer numbers a and b such that l ≤ a ≤ r and x ≤ b ≤ y there is a potion with experience a and cost b in the store (that is, there are (r - l + 1)·(y - x + 1) potions).

Kirill wants to buy a potion which has efficiency k. Will he be able to do this?

Input

First string contains five integer numbers l, r, x, y, k (1 ≤ l ≤ r ≤ 107, 1 ≤ x ≤ y ≤ 107, 1 ≤ k ≤ 107).

Output

Print "YES" without quotes if a potion with efficiency exactly k can be bought in the store and "NO" without quotes otherwise.

You can output each of the letters in any register.

Examples
input
1 10 1 10 1
output
YES
input
1 5 6 10 1
output
NO

从 x 扫到y

#include <iostream>#include <stdio.h>#include <algorithm>#include <cmath>#include <cstring>#include <string>#include <queue>#include <stack>#include <stdlib.h>#include <list>#include <map>#include <set>#include <bitset>#include <vector>#define mem(a,b) memset(a,b,sizeof(a))#define findx(x) lower_bound(b+1,b+1+bn,x)-b#define FIN      freopen("input.txt","r",stdin)#define FOUT     freopen("output.txt","w",stdout)#define S1(n)    scanf("%d",&n)#define SL1(n)   scanf("%I64d",&n)#define S2(n,m)  scanf("%d%d",&n,&m)#define SL2(n,m)  scanf("%I64d%I64d",&n,&m)#define Pr(n)     printf("%d\n",n)using namespace std;typedef long long ll;const double PI=acos(-1);const int INF=0x3f3f3f3f;const double esp=1e-6;const int maxn=1e6+5;const int MOD=1e9+7;const int mod=1e9+7;int dir[5][2]={0,1,0,-1,1,0,-1,0};ll inv[maxn*2],fac[maxn];ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll ans=exgcd(b,a%b,x,y);ll temp=x;x=y;y=temp-a/b*y;return ans;}ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}void INV(){inv[1] = 1;for(int i = 2; i < maxn; i++) inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;}void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){ x=1; y=0; d=a; }else{ ex_gcd(b,a%b,d,y,x); y-=x*(a/b);}}void Fac(){fac[0]=1;for(int i=1;i<=maxn;i++)fac[i]=(fac[i-1]*i)%MOD;}ll inv_exgcd(ll a,ll n){ll d,x,y;ex_gcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}ll inv1(ll b){return b==1?1:(MOD-MOD/b)*inv1(MOD%b)%MOD;}ll inv2(ll b){return qpow(b,MOD-2);}ll cal(ll m,ll n){if(m<n)return 0;return (fac[m]*inv[fac[n]]%MOD)%MOD*inv[fac[m-n]]%MOD;}ll cals(ll m,ll n){if(m<n)return 0;return (fac[m]*inv1(fac[n])%MOD)%MOD*inv1(fac[m-n])%MOD;}int main(){    ll l,r,x,y,k;    while(~scanf("%I64d %I64d %I64d %I64d %I64d",&l,&r,&x,&y,&k))    {        int flag=0;        for(ll i=x;i<=y;i++)        {            ll temp=k*i;            if(l<=temp&&temp<=r)            {                flag=1;                break;            }        }        if(flag)            printf("YES\n");        else            printf("NO\n");    }    return 0;}

B. Gleb And Pizza
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.

The pizza is a circle of radius r and center at the origin. Pizza consists of the main part — circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).

Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.

Input

First string contains two integer numbers r and d (0 ≤ d < r ≤ 500) — the radius of pizza and the width of crust.

Next line contains one integer number n — the number of pieces of sausage (1 ≤ n ≤ 105).

Each of next n lines contains three integer numbers xi, yi and ri ( - 500 ≤ xi, yi ≤ 500, 0 ≤ ri ≤ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri — radius of i-th peace of sausage.

Output

Output the number of pieces of sausage that lay on the crust.

Examples
input
8 477 8 1-7 3 20 2 10 -2 2-3 -3 10 6 25 3 1
output
2
input
10 840 0 90 0 101 0 11 0 2
output
0
Note

Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.



判断 在不在圆环里,   瞪着眼睛 愣是把 d 看成里面圆的半径,  更 可笑的是 还 过了5 个数据- - 


#include <iostream>#include <stdio.h>#include <algorithm>#include <cmath>#include <cstring>#include <string>#include <queue>#include <stack>#include <stdlib.h>#include <list>#include <map>#include <set>#include <bitset>#include <vector>#define mem(a,b) memset(a,b,sizeof(a))#define findx(x) lower_bound(b+1,b+1+bn,x)-b#define FIN      freopen("input.txt","r",stdin)#define FOUT     freopen("output.txt","w",stdout)#define S1(n)    scanf("%d",&n)#define SL1(n)   scanf("%I64d",&n)#define S2(n,m)  scanf("%d%d",&n,&m)#define SL2(n,m)  scanf("%I64d%I64d",&n,&m)#define Pr(n)     printf("%d\n",n)using namespace std;typedef long long ll;const double PI=acos(-1);const int INF=0x3f3f3f3f;const double esp=1e-6;const int maxn=1e6+5;const int MOD=1e9+7;const int mod=1e9+7;int dir[5][2]={0,1,0,-1,1,0,-1,0};struct node{ll x,y,r;ll  ed;}a[maxn];int main(){    int r,d,n;    while(~scanf("%d %d",&r,&d))    {    mem(a,0);scanf("%d",&n);ll ans=0;for(int i=1;i<=n;i++){scanf("%I64d %I64d %I64d",&a[i].x,&a[i].y,&a[i].r);a[i].ed=(a[i].x*a[i].x+a[i].y*a[i].y);if((r-d+a[i].r)*(r-d+a[i].r)<=a[i].ed&&((r-a[i].r)*(r-a[i].r))>=a[i].ed){ans++;}}printf("%I64d\n",ans);    }    return 0;}


原创粉丝点击