跳到正文

题解

题解:P14358 [CSP-J 2025] 座位 / seat(民间数据)

herezz约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
题目
P14358

版本

  1. v1当前

思路: 不难发现,如果当前排名是 RR,行数就是 (R−1)/n+1(R-1)/n+1,而列数分为两种情况:

  • 当行数为奇数时,列数为 (R−1)mod  n+1(R-1)\mod n+1;
  • 当行数为奇数时,列数为 n−(R−1)mod  nn-(R-1)\mod n。

代码:

C++
#include<bits/stdc++.h>
using namespace std;
int n,m,a[110],R;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n*m;i++)cin>>a[i];
    R=a[1];
    sort(a+1,a+n*m+1,greater<int>());//升序排序
    for(int i=1;i<=n*m;i++){
        if(a[i]==R){
            R=i;//回收利用
            break;
        }
    }
    cout<<(R-1)/n+1<<' ';
    if(((R-1)/n)%2==0)cout<<(R-1)%n+1;//这里因为去掉了+1,所以%2==0是奇数,%2==1是偶数
    else cout<<n-(R-1)%n;
    cout<<endl;
}
原文