Fruit Ninja
Fruit Ninja
- 描述
-
Fruit Ninja is a popular classic game. During the game, fruits will up to the air, and your aim is cut as more fruits as possible with a line.
Even if the line touch a point of a fruit, the fruit also be cut.- 输入
-
The first line is a number T(1<=T<=30), represents the number of case. The next T blocks follow each indicates a case.
The first line of each case contains one integer N (1<=N<=10)
Then N lines follow, each line contains a integer K(3<=K<=10), represent the number points of the fruit, then K*2 integers follow, each two integers represent one point of the fruit.(with anticlockwise order)
I promise all fruits are convex polygon, and any two fruit have no common point. - 输出
- For each case, output the number of case and the maximum fruits you could cut with a line.(as shown in the sample output)
- 样例输入
-
2 3 3 0 0 1 0 1 1 3 1 2 2 1 2 2 3 3 1 3 0 4 0 3 4 0 0 1 0 1 1 0 1 4 2 0 3 0 3 1 2 1 4 0 99 1 99 1 100 0 100
- 样例输出
-
Case 1: 3 Case 2: 2
-
思路:计算几何, 暴力求解, 遍历所有两两fruit上的点找直线与所有水果相交最多。
-
//nyoj 402#include <stdio.h>#define MAX_SIZE 31typedef struct Node {int x, y; }Pos;typedef struct ITEM {Pos pt[MAX_SIZE];int n; }Item;Item fruit[101];int iscolinear(Pos a, Pos b, Pos c) //判断ab, cb向量的位置 {return (a.x-b.x)*(c.y-b.y)-(a.y-b.y)*(c.x-b.x); }int isintersect(Pos a1, Pos a2, Pos b1, Pos b2) //判断a1a2, b1b2两条直线是否相交 {return iscolinear(a1, a2, b1)*iscolinear(a1, a2, b2) <= 0; }int getNum(Pos a, Pos b, int n) //遍历所有fruit, 获取与ab相交的个数 {int num = 0, m;for(int i = 0; i < n; i++){m = fruit[i].n;fruit[i].pt[m] = fruit[i].pt[0];for(int j = 0; j < m; j++){if(isintersect(a, b, fruit[i].pt[j], fruit[i].pt[j+1])){num++;break;}}}return num; }int main() {int t, n, m, i, j, ti, tj, ans, temp, cnt = 0;scanf("%d", &t);while(t--){ans = 0;scanf("%d", &n);for(i = 0; i < n; i++){scanf("%d", &m);fruit[i].n = m;for(j = 0; j < m; j++){scanf("%d%d", &fruit[i].pt[j].x, &fruit[i].pt[j].y);}}if(n == 1){printf("Case %d: 1\n", ++cnt);continue;}for(i = 0; i < n; i++) //遍历所有两两fruit上的点的连线用getNum()获取直线穿过水果的个数并更新ans{for(j = i+1; j < n; j++){for(ti = 0; ti < fruit[i].n; ti++){for(tj = 0; tj < fruit[j].n; tj++){temp = getNum(fruit[i].pt[ti], fruit[j].pt[tj], n);if(temp > ans){ans = temp;}}}}}printf("Case %d: %d\n", ++cnt, ans);}return 0; }
Fruit Ninja相关推荐
- Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)
Time Limit: 5000MS Memory limit: 65536K 题目描写叙述 Haveyou ever played a popular game named "Fruit ...
- 2018ACM上海大都会赛: A. Fruit Ninja(这绝对是道原题+随机)
题目描述 Fruit Ninja is a juicy action game enjoyed by millions of players around the world, with squish ...
- [2012山东ACM省赛] Fruit Ninja II (三重积分,椭球体积)
Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...
- Fruit Ninja(水果忍者)游戏源代码下载、分析(中)---可运行Android,Ios,Window,Mac,Html5平台
背景: 上一篇,已经实现了水果不断向上抛的效果和开始界面,这一篇我们将分析如何切水果,获得分数:运行demo需要配置好CocosEditor,暂不支持其他工具.demo是跨平台的,可移植运行andro ...
- Cocos2D实现Fruit Ninja里面刀光效果教程
Cocos2D实现Fruit Ninja里面刀光效果教程 2011-08-16 17:13 佚名 CocoaChina 我要评论(1) 字号:T | T Cocos2D实现Fruit Ninja里面刀 ...
- 另一种实现 Fruit Ninja 里刀光效果的方法
Fruit Ninja 这款游戏在 iOS 平台上取得了巨大成功,尤其是手指划过屏幕时的刀锋特效大大提升了情节相对简单的切水果游戏的视觉体验和整体印象.我们此前介绍了一种实现 Fruit Ninja ...
- Fruit Ninja(水果忍者)游戏源代码下载、分析(上)---可运行Android,Ios,Window,Mac,Html5平台
背景: 本来打算下一个游戏是涂鸦跳跃的,因为图片资源没准备好,暂时往后推迟.刚好笔者手头上有部分水果忍者的游戏素材,于是上周末花了一些时间把水果忍者实现了:以前读大学的时候这款游戏就风靡大街小巷,记得 ...
- 2011阿里巴巴程序设计公开赛 / 1002 Fruit Ninja
某神的代码: #include<stdio.h> #define max(x,y) (x)>(y)?(x):(y) #define min(x,y) (x)<(y)?(x):( ...
- 如何使用Box2D和Cocos2D制作一款像Fruit Ninja一样的游戏-第3部分
这篇文章还可以在这里找到 英语 Create a Sprite-Cutting Game with Cocos2D! 本篇教程是由iOS教程组的成员Allen Tan发布的,Allen是一位iOS开发 ...
最新文章
- 精确人工智能——核物理与粒子物理领域的新生力量
- iis worker process内存占用大_安卓模拟器磁盘空间占用大/内存空间不足
- jzoj3509-倒霉的小C【gcd,欧拉函数】
- 自己如何获取ADO连接字符串
- sqlserver可视化工具_数据分析之基础分析工具篇(修订版)
- c++语言while循环,c++ c语言while 循环语句入门基础教程
- 云服务器与传统服务器的优劣对比_为什么选择海外云服务器和香港云服务器
- Node.js下载安装及各种npm、cnpm、nvm、nrm配置(保姆式教程---提供全套安装包)---npm的安装与配置(2)
- 一图看完双11阿里云原生技术亮点
- hadoop菜鸟教程 Hadoop学习资料(云计算学习电子书)
- 人工神经网络的算法原理,人工神经网络算法步骤
- 中国裁判文书下载:selenium路线
- 我打算学计算机学英语,英语人教版八年级上册我打算学习计算机科学.doc
- 学Python兼职赚钱是真的吗
- 作战飞机效能评估系统-通用协同效能评估系统软件
- php判断百度来路,判断是否通过百度搜索进入你的网站 - 小俊学习网
- consider increasing the maximum size of the cache. After eviction approximately [10,239] KB of data
- 【原创】5.4青年有感
- 代码阅读——十个C开源项目
- 交通违章处罚归来 差4Km驾照就没有了,好险!
热门文章
- C# 利用Aspose.word导出word--基础篇
- 干货 | 携程移动直播探索
- [latex] latex应用
- 黑客如何掩盖 Linux 服务器上的操作痕迹
- 利用Sigrity PowerDC进行单板直流仿真--静态功率传输体系分析
- struct sockaddr和struct sockaddr_in区别
- js html 数据动态统计图,jquery实现动静态条形统计图
- 看steam游戏支持linux的网站,使用Steamy Cats对Linux上的Steam游戏进行分类
- BootStrap 怎样调整td的宽度
- vue项目中定义全局变量、函数的几种方法