• 冻死可怕了


    昨晚开始盖毛毯了。冻死了。

    接下来这个题目比较骚,然后就是通过打表找规律。

    链接:https://www.nowcoder.com/acm/contest/205/L
    来源:牛客网

    终于活成了自己讨厌的样子。

    这是她们都还没长大的时候发生的故事。那个时候,栗子米也不需要为了所谓的爱情苦恼。
    她们可以在夏日的午后,花大把的时间去研究生活中一些琐碎而有趣的事情,比如数论。
    有一天西柚柚问了栗子米一个题,她想知道中有多少不同的数,这些不同的数字里面第k大的是多少。

    输入描述:

    第一行一个整数T(T≤ 10

    5

    ),表示数据组数。
    每组数据第一行两个整数,表示n,k(1≤ n≤ 10

    18

    ),保证k不会超过不同的数字个数。

    输出描述:

    对于每组数据输出,输出两个整数,表示有多少个不同的数字和这里面第k大的是多少。

    示例1

    输入

    复制
    3
    1 1
    5 2
    67 8

    输出

    复制
    1 1
    3 2
    15 8
    打表:
    #include<bits/stdc++.h>
    #include<cstring>
    int const maxn=1e5;
    using namespace std;
    int func(int x){
        int f=-1;
        int cnt=0;
        for(int i=1;i<=x;i++){
            if(x/i!=f){
                cout<<x/i<<' ';
                cnt++;
                f=x/i;
            }
        }
        return cnt;
    } 
    int main(){
        int t;
        for(int i=1;i<=100;i++){
            t=func(i);
            cout<<endl;
            cout<<i<<' '<<t<<'*'<<endl;
        } 
    }
    

      规律:

    #include<bits/stdc++.h>
    #include<cstring>
    using namespace std;
    int main()
    {
        int n,k,m,t;
        double num;
        cin>>t;
        while(t--)
        {
            cin>>n>>k;
            if(k==0)
                break;
             num=sqrt(n);
            if(n/(int)num==(int)num)
            {
                m=(int)num*2-1;
            }
            else
                m=(int)num*2;
            if(k<=m/2)
                cout<<m<<" "<<n/k<<endl;
            else
                cout<<m<<" "<<m-k+1<<endl;
        }
        return 0;
    }

     然后这个题,开始图案都是‘.’,扫一遍给出的图案(枚举中心那个点),因为中心那个点是不会印上的,所以不用管它,只要中心点的周围一圈全都是'#',那么我们就可以印,就在我们的图案上,把这一圈都赋为‘#’。最后把我们画出的图和原图案比对,如果一致就是YES,否则就是NO

    B. Forgery
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it?

    For simplicity, the signature is represented as an n×mn×m grid, where every cell is either filled with ink or empty. Andrey's pen can fill a 3×33×3square without its central cell if it is completely contained inside the grid, as shown below.


    xxx
    x.x
    xxx

    Determine whether is it possible to forge the signature on an empty n×mn×m grid.

    Input

    The first line of input contains two integers nn and mm (3n,m10003≤n,m≤1000).

    Then nn lines follow, each contains mm characters. Each of the characters is either '.', representing an empty cell, or '#', representing an ink filled cell.

    Output

    If Andrey can forge the signature, output "YES". Otherwise output "NO".

    You can print each letter in any case (upper or lower).

    Examples
    input
    Copy
    3 3
    ###
    #.#
    ###
    output
    Copy
    YES
    input
    Copy
    3 3
    ###
    ###
    ###
    output
    Copy
    NO
    input
    Copy
    4 3
    ###
    ###
    ###
    ###
    output
    Copy
    YES
    input
    Copy
    5 7
    .......
    .#####.
    .#.#.#.
    .#####.
    .......
    output
    Copy
    YES
    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    char a[1001][1001];
    char t[1001][1001];
    int dx[]= {-1,0,1};
    int dy[]= {-1,0,1};
    int n,m;
    int kepa(int x,int y)
    {
        int i,j;
        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                if(i==1&&j==1)
                    continue;
                if(x+dx[i]<1||x+dx[i]>n||y+dy[i]<1||y+dy[i]>m||a[x+dx[i]][y+dy[j]]!='#')
                    return 0;
            }
        }
        return 1;
    }
    void seqing(int x,int y)
    {
        int i,j;
        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                if(i==1&&j==1)
                    continue;
                t[x+dx[i]][y+dy[j]]='#';
            }
        }
    }
    int main()
    {
        int i,j;
        cin>>n>>m;
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                cin>>a[i][j];
            }
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                t[i][j]='.';
            }
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(kepa(i,j))
                    seqing(i,j);
            }
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(a[i][j]!=t[i][j])
                    {
                        cout<<"NO"<<endl;
                        return 0;
                    }
            }
        }
            cout<<"YES"<<endl;
        return 0;
    }

     这个题,是状态压缩DP,因为最多只有15门课程,可以使用二进制来表示所有完成的状况

    例如5,二进制位101,代表第一门和第三门完成了,第二门没有完成,那么我们可以枚举1~1<<n便可以得出所有的状态

    然后对于每一门而言,其状态是t = 1<<i,我们看这门在现在的状态s下是不是完成,可以通过判断s&t是否为1来得到

    当得出t属于s状态的时候,我们便可以进行DP了,在DP的时候要记录路径,方便之后的输出

    因为字母是从小到大排的,所以当扣分一样的时候,顺序从后往前排的时候所以一个状态i尽量选靠大的字符串,这样子输出的时候从就会按照 要求从小的字符串到大的字符串输出了,这个地方应该多看几遍才能看懂。

    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #include<stack>
    #define inf 0x3f3f3f
    using namespace std;
    stack<int> st;
    struct node
    {
        string s;
        int day;
        int num;
    }a[20];
    struct node2
    {
        int father;
        int id;
        int time;
        int sore;
    }dp[1<<15];
    int main()
    {
        int n,t,i,j;
        cin>>t;
        while(t--)
        {
            cin>>n;
            for(i=0;i<n;i++)
            {
                cin>>a[i].s>>a[i].day>>a[i].num;
            }
            int end=1<<n;
            for(i=1;i<end;i++)
            {
                dp[i].sore=inf;
                for(j=n-1;j>=0;j--)
                {
                    int temp=1<<j;
                   if(temp&i)
                   {
                       int tem=i-temp;
                     int tt=dp[tem].time+a[j].num-a[j].day;
                     if(tt<0)
                        tt=0;
                    if(tt+dp[tem].sore<dp[i].sore)
                    {
                        dp[i].sore=tt+dp[tem].sore;
                        dp[i].father=tem;
                        dp[i].id=j;
                        dp[i].time=dp[tem].time+a[j].num;
                    }
                   }
                }
            }
            int ans=end-1;
            cout<<dp[ans].sore<<endl;
            while(dp[ans].time)
            {
               st.push(dp[ans].id);
                ans=dp[ans].father;
            }
            while(!st.empty())
            {
               int cnt=st.top();
               cout<<a[cnt].s<<endl;
                st.pop();
            }
        }
        return 0;
    }
  • 相关阅读:
    为MySQL的root用户设定密码
    Sublime Text 3安装Package Control失败
    从系统关机后主机仍在运行
    如何判断一个数是否是质数?
    python之lambda函数
    yum的一些命令使用方法
    NopCommerce架构分析-数据持久层
    NopCommerce架构分析-Cache的应用
    NopCommerce架构分析-源码结构和架构
    下载图片
  • 原文地址:https://www.cnblogs.com/kepa/p/9753797.html
Copyright © 2020-2023  润新知