给一个n*n的数字矩阵 然后1到n^2/2的就从左到右 从上到下依次放在行列加起来是偶数的格子里 然后n^2/2+1的就放在奇数格子里
然后询问某个格子的数是多少
其实就是根据n是奇数还是偶数 还有询问的位置是奇数还是偶数然后推理一下 找一下规律即可
最后答案要开long long 而n也要开long long 不然中间结果会溢出

#include <bits/stdc++.h>using namespace std;const int maxn=1e9+10;long long n,m;int main()
{ios::sync_with_stdio(false);cin>>n>>m;while(m--){long long ans=0;long long x,y;cin>>x>>y;ans=(x-1)*n+y+1;if((x+y)%2==1){ans+=n*n;}cout<<ans/2<<endl;}return 0;
}

  

转载于:https://www.cnblogs.com/Fy1999/p/9574930.html

codeforces 1027 B - Numbers on the Chessboard(规律)相关推荐

  1. 【CodeForces - 1027B 】Numbers on the Chessboard (没有营养的找规律题,无聊题)

    题干: You are given a chessboard of size n×nn×n. It is filled with numbers from 11 to n2n2 in the foll ...

  2. B. Numbers on the Chessboard -codeforces1027 -csdn博客

    B. Numbers on the Chessboard -codeforces1027 -csdn博客 You are given a chessboard of size n×n. It is f ...

  3. Numbers on the Chessboard

    You are given a chessboard of size n×nn×n. It is filled with numbers from 11 to n2n2 in the followin ...

  4. Numbers on the Chessboard(CF-1027B)

    Problem Description You are given a chessboard of size n×n. It is filled with numbers from 1 to n^2  ...

  5. CF1027B Numbers on the Chessboard (#数学)

    题目描述 You are given a chessboard of size n \times nn×n . It is filled with numbers from 11 to n^2n2 i ...

  6. CodeForces - 55D Beautiful numbers

    题目链接:http://codeforces.com/problemset/problem/55/D 题意:求区间[L,R]有多少个Beautiful numbers.Beautiful number ...

  7. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  8. CodeForces - 165E Compatible Numbers(SOSdp)

    题目链接:点击查看 题目大意:给出 nnn 个数,问能否在数列中找到一个数,满足 ai&aj=0a_i\& a_j=0ai​&aj​=0 题目分析:题目中的式子可以转换为,ai ...

  9. CodeForces - 768B Code For 1(找规律)

    题目链接:http://codeforces.com/problemset/problem/768/B点击打开链接 B. Code For 1 time limit per test 2 second ...

最新文章

  1. python在bim中的应用_Revit元素类别——Dynamo Python系列教程(六)
  2. .NET深入学习笔记(3):垃圾回收与内存管理
  3. java都界面相对布局_浏览器的重排和重绘
  4. referenced from 异常
  5. win7系统怎么获取system权限?
  6. java必读书籍_最佳5本Java性能调优书籍–精选,必读
  7. 将Spring 3.x和Hibernate 3.x升级到Spring Platform 1.0.1(Spring + hibernate 4.x)
  8. 《Java技术》第八次作业
  9. python sklearn: 模型(如 SVM,PCA等)的保存与加载调用
  10. Windows 10 下使用 telnet 客户端/服务端工具进行连接
  11. 各地级市系列环境指标数据(2003-2017年)
  12. 免费软件时代的来临!可以媲美金蝶用友的ERP产品,完全免费使用。
  13. python 读取多个excel数据写入同一个excel中
  14. java的耦合与解耦
  15. vue前端实现上传文件的两种方式
  16. 搜索切换dump之MapReduce讲解
  17. 一个前腾讯员工的百万年薪之路
  18. quartz mysql 操作_Quartz 定时任务使用 —— 数据库各表字段的含义(十五)
  19. 网站推广-----100个基本推广方法
  20. Arduino开发之如何连接继电器模块?

热门文章

  1. ZYAR20A 亚克力2驱 蓝牙 298寻迹避障机器人 ——材料清单
  2. Java面向对象(三)Static
  3. 【Qt】简单Qt文本查找功能
  4. 【ARM】Tiny4412裸板编程之Chip ID
  5. 【Qt】Qt数据库简介
  6. oracle10g的silent,Linux 静默(Silent) 安装Oracle 10g
  7. 8个适合新手入门的python项目2020_8个适合新手入门的Python项目(2020.6)
  8. android sd大小,android用户的SD卡相同容量是否完全一样的大小
  9. Qt5.0中lineEdit的输入输出
  10. 【设计模式】C++单例模式