zoukankan      html  css  js  c++  java
  • 上海大都赛清题

    A fruit ninja
    Fruit Ninja is a juicy action game enjoyed by millions of players around the world, with squishy,
    splat and satisfying fruit carnage! Become the ultimate bringer of sweet, tasty destruction with every slash.
    Fruit Ninja is a very popular game on cell phones where people can enjoy cutting the fruit by touching the screen.
    In this problem, the screen is rectangular, and all the fruits can be considered as a point. A touch is a straight line cutting
    thought the whole screen, all the fruits in the line will be cut.
    A touch is EXCELLENT if ≥ x, (N is total number of fruits in the screen, M is the number of fruits that cut by the touch, x is a real number.)
    Now you are given N fruits position in the screen, you want to know if exist a EXCELLENT touch.
    
    

    输入描述:

    
    
    The first line of the input is T(1≤ T ≤ 100), which stands for the number of test cases you need to solve.
    The first line of each case contains an integer N (1 ≤ N ≤ 10
    4
    ) and a real number x (0 < x < 1), as mentioned above.
    The real number will have only 1 digit after the decimal point.
    The next N lines, each lines contains two integers x
    i
     and y
    i
     (-10
    9
     ≤ x
    i
    ,y
    i
     ≤ 10
    9
    ), denotes the coordinates of a fruit.
    
    

    输出描述:

    
    
    For each test case, output "Yes" if there are at least one EXCELLENT touch. Otherwise, output "No".
    
    
    示例1

    输入

    复制
    2
    5 0.6
    -1 -1
    20 1
    1 20
    5 5
    9 9
    5 0.5
    -1 -1
    20 1
    1 20
    2 5
    9 9

    输出

    复制
    Yes
    No
    这题随机化。为什么随机化?
    看题目 的概率只有0.1-0.9;9种情况
    我们想10000个点*0.9是9000个要求在一条直线上。
    0.1是要求1000个点在一条直线上。
    我们随机1000个点是不是大概率能在这条直线上;


    #include<iostream> #include<stdio.h> #include <stdlib.h> #include <time.h> #include<cmath> #define eps 1e-9 using namespace std; struct node { double x; double y; }point[200000]; int Xc(int x1, int y1, int x2, int y2) { return x1*y2-x2*y1; } int main() { int t; scanf("%d",&t); while(t--) { int n; double m; scanf("%d%lf",&n,&m); for(int i=0;i<n;i++) { scanf("%lf%lf",&point[i].x,&point[i].y); } int pp=1500; int flag=0; while(pp--) { int xx=rand()%n; int yy=rand()%n; if(xx==yy) continue; int ans=0; for(int i=0;i<n;i++) { if(Xc(point[i].x-point[xx].x, point[i].y-point[xx].y, point[yy].x-point[xx].x, point[yy].y-point[xx].y)==0) ans++; } if(n*m*1.0<=ans) { flag=1; break; } } if(flag==1) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
    链接:https://www.nowcoder.com/acm/contest/163/F
    来源:牛客网

    There is a matrix A that has N rows and M columns. Each grid (i,j)(0 ≤ i < N, 0 ≤ j < M) is painted in white at first.
    Then we perform q operations:
    For each operation, we are given (xc, yc) and r. We will paint all grids (i, j) that meets to black.
    You need to calculate the number of white grids left in matrix A.

    输入描述:

    The first line of the input is T(1≤ T ≤ 40), which stands for the number of test cases you need to solve.
    The first line of each case contains three integers N, M and q (1 ≤ N, M ≤ 2 x 104; 1 ≤ q ≤ 200), as mentioned above.
    The next q lines, each lines contains three integers x
    c
    , y
    c
     and r (0 ≤ x
    c
     < N; 0 ≤ y
    c
     < M; 0 ≤ r ≤ 10
    5
    ), as mentioned above.

    输出描述:

    For each test case, output one number.
    示例1

    输入

    复制
    2
    39 49 2
    12 31 6
    15 41 26
    1 1 1
    0 0 1

    输出

    复制
    729
    0

    拿线去扫圆;区间区间算
    #include<math.h> #include<stdio.h> #include<algorithm> using namespace std; int n,m,q; struct node { int x,y,r; }a[205]; struct node1 { int l,r; }b[1005]; bool cmp(node1 a,node1 b) { if(a.l==b.l) return a.r<b.r; return a.l<b.l; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%d%d%d",&n,&m,&q); for(int i=0;i<q;i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].r); int ans=0; for(int i=0;i<n;i++) { int w,cnt=0; double h; for(int j=0;j<q;j++) { if(abs(i-a[j].x)>a[j].r) continue; w=abs(i-a[j].x); h=sqrt(a[j].r*a[j].r-w*w); int q=ceil(a[j].y-h); int p=floor(a[j].y+h); b[++cnt].l=max(0,q); b[cnt].r=min(m-1,p); } sort(b+1,b+cnt+1,cmp); int l=0;int r=0; if(cnt) ans+=b[1].r-b[1].l+1; for(int j=2;j<=cnt;j++) { if(b[j-1].r>=b[j].l) b[j].l=b[j-1].r+1; if(b[j].r>=b[j].l) ans+=b[j].r-b[j].l+1; b[j].r=max(b[j].r,b[j-1].r); } } printf("%d ",n*m-ans); } }
  • 相关阅读:
    codevs 1086 栈 2003年NOIP全国联赛普及组
    1200 同余方程 2012年NOIP全国联赛提高组
    【bzoj4939】【YNOI2016】掉进兔子洞(莫队)
    洛谷P3674 小清新人渣的本愿(莫队)
    Lucas卢卡斯定理
    组合数学习笔记
    洛谷P3178 [HAOI2015]树上操作(线段树)
    洛谷P3258 [JLOI2014]松鼠的新家(树上差分+树剖)
    洛谷P2526 [SHOI2001]小狗散步(二分图匹配)
    bzoj3140: [Hnoi2013]消毒(二分图)
  • 原文地址:https://www.cnblogs.com/2014slx/p/9454201.html
Copyright © 2011-2022 走看看