Queen Collision

该问题涉及在n*n的棋盘上放置皇后棋,并计算由于处于同一行、列或对角线而发生的碰撞数量。输入包含棋盘大小n和线性皇后模式的数量g,以及每个模式的详细坐标。输出是所有碰撞的计数。样例输入和输出分别对应了不同的棋盘配置。

Description

   Lots of time has been spent by computer science students dealing with queens on a chess board. Two queens on a chessboard collide if they lie on the same row, column or diagonal, and there is no piece between them. Various sized square boards and numbers of queens are considered. For example, Figure 1, with a 7 × 7 board, contains 7 queens with no collisions. In Figure 2 there is a 5 × 5 board with 5 queens and 4 collisions. In Figure 3, a traditional 8 × 8 board, there are 7 queens and 5 collisions.

                                  

   On an n × n board, queen positions are given in Cartesian coordinates (x, y) where x is a column number, 1 to n, and y is a row number, 1 to n. Queens at distinct positions (x1, y1) and (x2, y2) lie on the same diagonal if (x1 − x2) and (y1 − y2) have the same magnitude. They lie on the same row or column if x1 = x2 or y1 = y2, respectively.

  In each of these cases the queens have a collision if there is no other queen directly between them on the same diagonal, row, or column, respectively. For example, in Figure 2, the collisions are between the queens at (5, 1) and (4, 2), (4, 2) and(3, 3), (3, 3) and (2, 4), and finally (2, 4) and (1, 5). In Figure 3, the collisions are between the queens at (1, 8) and (4, 8), (4, 8) and (4, 7), (4, 7) and (6, 5),(7, 6) and (6, 5), and finally (6, 5) and (2, 1).

  Your task is to count queen collisions. In many situations there are a number of queens in a regular pattern. For instance in Figure 1 there are 4 queens in a line at (1,1), (2, 3), (3, 5), and (4, 7). Each of these queens after the first at (1, 1) is one to the right and 2 up from the previous one. Three queens starting at (5, 2) follow a similar pattern. Noting these patterns can allow the positions of a large number of queens to be stated succinctly.

Input

   The input will consist of one to twenty data sets, followed by a line containing only ‘0’.

   The first line of a dataset contains blank separated positive integers n g, where n indicates an n×n board size, and g is the number of linear patterns of queens to be described, where n < 30000, and g < 250. The next g lines each contain five blank separated integers, k x y s t, representing a linear pattern of k queens at locations (x + i ∗ s, y + i ∗ t), for i = 0, 1, . . . , k − 1. The value of k is positive. If k is 1, then the values of s and t are irrelevant, and they will be given as ‘0’. All queen positions will be on the board. The total number of queen positions among all the linear patterns will be no more than n, and all these queen positions will be distinct.

Output

   There is one line of output for each data set, containing only the number of collisions between the queens. The sample input data set corresponds to the configuration in the Figures. Take some care with your algorithm, or else your solution may take too long.

Sample Input

7 2

4 1 1 1 2

3 5 2 1 2

5 1

5 5 1 -1 1

8 3

1 2 1 0 0

3 1 8 3 -1

3 4 8 2 -3

0

Sample Output

0

4

5

解析

  大致题意是在一个n*n的棋盘中放入g个皇后棋,每个皇后棋的坐标是 (x + i ∗ s, y + i ∗ t) for i = 0, 1, . . . , k − 1。若有任意两个皇后棋在同一行或同一列或同一条对角线,那么视这两个皇后为碰撞,输出的最终结果是碰撞的皇后棋的个数。

代码

#include<stdio.h>
#include<string.h>
#define MAX 40000
int main()
{
    int n,T;
    while(~scanf("%d",&n))
    {
        if(n==0) break;
        scanf("%d",&T);
        int row[MAX],col[MAX],dia[2*MAX],obdia[2*MAX];
        //row数组记录在同行出现的皇后棋数,col记录在同列出现的皇后棋数,dia数组记录在同条对角线
        //出现的皇后棋数,obdia记录在同条斜对角线出现的皇后棋数
        memset(row,0,sizeof(row));
        memset(col,0,sizeof(col));
        memset(dia,0,sizeof(dia));
        memset(obdia,0,sizeof(obdia));
        int k,x,y,s,t,i;
        while(T--)
        {
            scanf("%d%d%d%d%d",&k,&x,&y,&s,&t);
            int tempx,tempy;
            for(i=0;i<k;i++)
            {
                tempx=x+i*s; //皇后棋的横坐标
                tempy=y+i*t; //皇后棋的纵坐标
                row[tempx]+=1;
                col[tempy]+=1;
                dia[tempx+tempy]+=1; //对角线
                obdia[tempx-tempy+n]+=1; //斜对角线
            }
        }
        int ans=0;
        for(i=1;i<=n;i++)
        {
            if(row[i]>1)
                ans+=row[i]-1;
            if(col[i]>1)
                ans+=col[i]-1;
        }
        for(i=1;i<2*n;i++)
        {
            if(dia[i]>1)
                ans+=dia[i]-1;
            if(obdia[i]>1)
                ans+=obdia[i]-1;
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

内容概要:本文介绍了ENVI Deep Learning V1.0的操作教程,重点讲解了如何利用ENVI软件进行深度学习模型的训练与应用,以实现遥感图像中特定目标(如集装箱)的自动提取。教程涵盖了从数据准备、标签图像创建、模型初始化与训练,到执行分类及结果优化的完整流程,并介绍了精度评价与通过ENVI Modeler实现一键化建模的方法。系统基于TensorFlow框架,采用ENVINet5(U-Net变体)架构,支持通过点、线、面ROI或分类图生成标签数据,适用于多/高光谱影像的单一类别特征提取。; 适合人群:具备遥感图像处理基础,熟悉ENVI软件操作,从事地理信息、测绘、环境监测等相关领域的技术人员或研究人员,尤其是希望将深度学习技术应用于遥感目标识别的初学者与实践者。; 使用场景及目标:①在遥感影像中自动识别和提取特定地物目标(如车辆、建筑、道路、集装箱等);②掌握ENVI环境下深度学习模型的训练流程与关键参数设置(如Patch Size、Epochs、Class Weight等);③通过模型调优与结果反馈提升分类精度,实现高效自动化信息提取。; 阅读建议:建议结合实际遥感项目边学边练,重点关注标签数据制作、模型参数配置与结果后处理环节,充分利用ENVI Modeler进行自动化建模与参数优化,同时注意软硬件环境(特别是NVIDIA GPU)的配置要求以保障训练效率。
### Unity 中的碰撞检测与处理 在 Unity 的物理引擎中,`Collision Detection` 是指两个具有 `Collider` 和 `Rigidbody` 的物体之间的交互过程。以下是关于如何有效使用和优化 Unity 中的碰撞检测机制的相关信息。 #### 1. 碰撞事件及其触发条件 Unity 提供了三种主要的碰撞回调函数来响应不同阶段的碰撞行为: - **OnCollisionEnter**: 当一个带有刚体或 Collider 的对象首次与其他对象发生接触时调用此方法[^1]。 ```csharp void OnCollisionEnter(Collision collision) { Debug.Log($"开始碰撞到对象: {collision.gameObject.name}"); foreach (ContactPoint contact in collision.contacts) { Debug.DrawRay(contact.point, contact.normal, Color.red); } } ``` - **OnCollisionStay**: 如果两个对象保持接触状态,则每一帧都会调用该方法[^1]。 - **OnCollisionExit**: 当两者的接触结束时会调用这个方法[^1]。 这些方法都接收一个名为 `Collision` 的参数,它提供了丰富的数据结构用于获取详细的碰撞信息,比如接触点的位置、法向量以及相对速度等。 #### 2. 物理更新频率调整 为了提高性能并减少不必要的计算开销,可以考虑修改固定时间步长(`Fixed Delta Time`)设置。通过进入菜单栏路径 `Edit->Project Settings->Time`, 可以将固定的更新间隔设定在一个合理的范围内(通常建议介于0.04至0.067秒之间),从而降低每秒钟执行 FixedUpdate 方法次数的同时也减少了物理引擎对于碰撞探测及刚体刷新操作的要求[^3]。 另外值得注意的是如果角色模型本身关联了一个 Rigidbody 组件的话还可以开启插值选项(interpolation), 这样即使采用较低的时间分辨率也能获得较为流畅的画面效果. #### 3. 输入控制集成实例分析 下面展示了一段简单的玩家控制器脚本示例,展示了如何结合新的输入系统读取方向键或者手柄摇杆的数据,并将其应用到实际运动逻辑当中去[^2]: ```csharp using System.Collections; using UnityEngine; public class PlayerMovement : MonoBehaviour { public float speed = 5f; private Vector2 movementInput; void Start() { // 初始化 InputAction 并启用 var playerControls = new PlayerInputControl(); playerControls.Enable(); playerControls.Gameplay.Move.performed += ctx => movementInput = ctx.ReadValue<Vector2>(); playerControls.Gameplay.Move.canceled += ctx => movementInput = Vector2.zero; } void FixedUpdate() { MovePlayer(movementInput); } void MovePlayer(Vector2 direction) { transform.Translate(direction.normalized * speed * Time.fixedDeltaTime, Space.World); } } ``` 以上代码片段定义了一个基本的角色移动框架,其中利用现代 API 来捕获用户的按键动作并将它们映射成相应的位移矢量。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值