zoukankan      html  css  js  c++  java
  • SGU

    题目链接:https://vjudge.net/contest/239445#problem/H

    题目大意:输入n,k,有n*n* n*n的网格,要求每行每列刚好有k个*,每n*n的小方格内也刚好有k个*。

    思路:不是自己写出来的,大概思路就是从第一排开始放,放满k个,然后跳到下一行,在这行的基础上加上n的位置开始放,放满k个,····一直下去,当到了第i行,并且i%n==1时,从上一个i%n==1的位置的下一个位置开始放,思路就是这样了

    看代码

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<stdio.h>
    #include<string.h>
    #include<cmath>
    #include<math.h>
    #include<algorithm>
    #include<set>
    #include<queue>
    #include<map>
    typedef long long ll;
    using namespace std;
    const ll mod=1e9+7;
    const int maxn=4e2+10;
    const int maxk=100+10;
    const int maxx=1e4+10;
    const ll maxe=1000+10;
    #define INF 0x3f3f3f3f3f3f
    int main()
    {
        int n,k,ac=1,flag=1;
        int a[maxn][maxn];
        memset(a,0,sizeof(a));
        cin>>n>>k;
        for(int i=1;i<=n*n;i++)
        {
            if(i>1&&i%n==1) {flag++;ac=flag;}//当到了i%n==1时,从上一个i%n==1的位置的下一个开始放,当然i=1除外
                for(int l=ac;l<ac+k;l++)
                {
                    int z=l;
                    if(z>(n*n)) z=z%(n*n);
                    a[i][z]=1;
                }
                ac=ac+n;//下一行跳n个放
                if(ac>n*n) ac=ac%(n*n);
    
        }
        for(int i=1;i<=n*n;i++)
        {
            for(int j=1;j<=n*n;j++)
            {
                if(a[i][j]) cout<<"*";
                else cout<<".";
            }
            cout<<endl;
        }
        return 0;
    }

    下面是题目:

    The Berland is in trouble again. After the recent elections All-Berland Great Duma has divided into two coalitions: Blue-eyed coalition and Red-eyed coalition. On the independence day the following question was raised: what will the national flag look like? Both coalitions agreed that the flag should be a square of N 2 x N 2 cells, each of them painted blue of red. To make the flag acceptable for both coalitions, the following requirements must be held:

    • every row of the flag must contain exactly K blue cells
    • every column of the flag must contain exactly K blue cells
    • if we split the flag into squares of N x N cells (there will be N x N such squares), then every such square must contain exactly K blue cells. You are the chief programmers in Berland. So, making the flag model is your duty.
      Input
      First line of the input contains two integer numbers N and K (1 ≤ N ≤ 20, 0 ≤ KN2).
      Output
      Output description of the desired flag. Print N2 lines which consist of N2 characters
      '*'
      and
      '.'
      , where
      '*'
      means blue cell and
      '.'
      means red cell. Output
      "NO SOLUTION"
      (without quotes), if there is no flag which satisfies both coalitions. If there are several solutions, output any of them.
      Example(s)
      sample input
      sample output
      2 2
      
      *..*
      .**.
      .**.
      *..*
      

      sample input
      sample output
      3 1
      
      *........
      ...*.....
      ......*..
      .*.......
      ....*....
      .......*.
      ..*......
      .....*...
      ........*
      
    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    Excel导出失败的提示
    C#中将一个引用赋值null的作用
    POJ2112Optimal Milking(二分法+floyd最短+网络流量)
    三年流水账
    OpenCV(C++接口)学习笔记1-图像读取、显示、保存
    thinkphp3.2 代码生成并点击验证码
    8.19! 今天我有18生日,点击阅读或顶部 尾随幸运的一天!生日知识!↓——【Badboy】
    如何系统地学习JavaScript
    HDU 3065 病毒在继续 (AC自己主动机)
    使用Canvas和Paint自己绘制折线图
  • 原文地址:https://www.cnblogs.com/caijiaming/p/9394606.html
Copyright © 2011-2022 走看看