上海大都赛清题

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 (x c, y c) 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 10 4; 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",n*m-ans); } }

 

转载于:https://www.cnblogs.com/2014slx/p/9454201.html

内容概要:本文系统介绍了算术优化算法(AOA)的基本原理、核心思想及Python实现方法,并通过图像分割的实际案例展示了其应用价值。AOA是一种基于种群的元启发式算法,其核心思想来源于四则运算,利用乘除运算进行全局勘探,加减运算进行局部开发,通过数学优化器加速函数(MOA)和数学优化概率(MOP)动态控制搜索过程,在全局探索与局部开发之间实现平衡。文章详细解析了算法的初始化、勘探与开发阶段的更新策略,并提供了完整的Python代码实现,结合Rastrigin函数进行测试验证。进一步地,以Flask框架搭建前后端分离系统,将AOA应用于图像分割任务,展示了其在实际工程中的可行性与高效性。最后,通过收敛速度、寻优精度等指标评估算法性能,并提出自适应参数调整、模型优化和并行计算等改进策略。; 适合人群:具备一定Python编程基础和优化算法基础知识的高校学生、科研人员及工程技术人员,尤其适合从事人工智能、图像处理、智能优化等领域的从业者;; 使用场景及目标:①理解元启发式算法的设计思想与实现机制;②掌握AOA在函数优化、图像分割等实际问中的建模与求解方法;③学习如何将优化算法集成到Web系统中实现工程化应用;④为算法性能评估与改进提供实践参考; 阅读建议:建议读者结合代码逐行调试,深入理解算法流程中MOA与MOP的作用机制,尝试在不同测试函数上运行算法以观察性能差异,并可进一步扩展图像分割模块,引入更复杂的预处理或后处理技术以提升分割效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值