zoukankan      html  css  js  c++  java
  • 【CF1027B】Numbers on the Chessboard(数学)

    题意:给定一个n*n的矩阵与生成矩阵的方式,多次询问同一个方格内(x,y)的数字是多少

    题意:浪费人生的矩阵题,找规律

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<string>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<map>
     8 #include<set>
     9 #include<queue>
    10 #include<vector>
    11 using namespace std;
    12 typedef long long ll;
    13 typedef unsigned int uint;
    14 typedef unsigned long long ull;
    15 typedef pair<int,int> PII;
    16 typedef vector<int> VI;
    17 #define fi first
    18 #define se second 
    19 #define MP make_pair
    20 #define N   410000
    21 #define MOD 1000000007
    22 #define eps 1e-8 
    23 #define pi acos(-1)
    24 #define oo 110000000000000
    25 
    26 char c[N][2],a[N];
    27 int b[N];
    28 
    29 int read()
    30 { 
    31    int v=0,f=1;
    32    char c=getchar();
    33    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
    34    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
    35    return v*f;
    36 }
    37 
    38 
    39 void swap(int &x,int &y)
    40 {
    41     int t=x;x=y;y=t;
    42 }
    43 
    44 
    45 
    46 int main()
    47 {
    48     //freopen("1.in","r",stdin);
    49 //    freopen("1.out","w",stdout);
    50     ll n;
    51     int q;
    52     scanf("%lld%d",&n,&q);
    53     while(q--)
    54     {
    55         ll x,y;
    56         scanf("%lld%lld",&x,&y);
    57         ll s1=n%2;
    58         ll s2=x%2;
    59         ll s3=y%2;
    60         ll ans;
    61         if(s1&&s2&&s3) ans=(x-1)/2*n+(y+1)/2;
    62         if(s1&&s2&&s3==0) ans=(n*n+1)/2+x/2*n+y/2;
    63         if(s1&&s2==0&&s3) ans=(n*n+1)/2+x/2*n+y/2-n/2;
    64         if(s1&&s2==0&&s3==0) ans=x/2*n+y/2-n/2;
    65         if(s1==0&&s2&&s3) ans=(x-1)/2*n+(y+1)/2;
    66         if(s1==0&&s2&&s3==0) ans=(n*n+1)/2+x/2*n+y/2;
    67         if(s1==0&&s2==0&&s3) ans=(n*n+1)/2+x/2*n+y/2-n/2+1;
    68         if(s1+s2+s3==0) ans=x/2*n+y/2-n/2;
    69         printf("%lld
    ",ans);  
    70     }
    71     return 0;
    72 }
  • 相关阅读:
    hdu6229 Wandering Robots 2017沈阳区域赛M题 思维加map
    hdu6223 Infinite Fraction Path 2017沈阳区域赛G题 bfs加剪枝(好题)
    hdu6438 Buy and Resell 买卖物品 ccpc网络赛 贪心
    hdu6441 Find Integer 求勾股数 费马大定理
    bzoj 1176 Mokia
    luogu 3415 祭坛
    bzoj 1010 玩具装箱
    bzoj 3312 No Change
    luogu 3383【模板】线性筛素数
    bzoj 1067 降雨量
  • 原文地址:https://www.cnblogs.com/myx12345/p/9843869.html
Copyright © 2011-2022 走看看