A。水题。

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include<algorithm>
using namespace std;
];
int main()
{
    int n,m;
    cin>>n>>m;
    ; i<=n; ++i) cin>>a[i];
    ;
    ;
    ; i<=n; ++i)
    {
        if(p<a[i])
        {
            p=m;
            ans++;
        }
        p-=a[i];
    }
    cout<<ans<<endl;
    ;
}

B。用字符串读入数字。对于这个数字,从左往右看,寻找交换k次之内可得的最大数字,并交换到最左边。k再减去交换步数。如此直到k为0或者该数字达它可取的最大值。

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include<algorithm>
using namespace std;
string num;
int k;
int main()
{
    cin>>num>>k;
    ) cout<<num<<endl;
    else
    {
        string t=num;
        sort(t.begin(),t.end(),greater<int>());
        ;
        int len=num.size();
        while(k)
        {
            if(num==t) break;
            int maxp=st;
            ; i<min(st+k+,len); ++i)
                if(num[i]>num[maxp]) maxp=i;
            for(int i=maxp; i>st; --i)
            {
                swap(num[i],num[i-]);
                k--;
            }
            st++;
        }
        cout<<num<<endl;
    }
    ;
}

C。根据计算出的数字对,画一个图。

首先计算出所有的数字对,由于有负数,为了方便可以用map<int,int>来存图。取得点可能的上下左右边界值,再遍历该空间,画图即可。

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> Pair;
map<Pair,int > vis;
];
int main()
{
    int n;
    cin>>n;
    ; i<=n; ++i) cin>>a[i];
    ,left=,down=,right=;
    ,y=;
    vis[Pair(x,y)]=;
    ; i<=n; ++i)
    {
        ; j<=a[i]; ++j)
        {
            x++;
            ) y++;
            else y--;
            )
                vis[Pair(x,y)]=;
            else
                vis[Pair(x,y+)]=-;
        }
        up=max(up,y);
        down=min(down,y);
        left=min(left,x);
        right=max(right,x);
    }
    for(int i=up; i>down; --i)
    {
        ; j<=right; ++j)
        {
            int &u=vis[Pair(j,i)];
            )  cout<<"/";
            )  cout<<"\\";
            else  cout<<" ";
        }
        cout<<endl;
    }
    ;
}

D。预处理+统计。

统计三角形个数。要求选定的三角形的边上不含有黑点。

明显这样图中的三角形只能是等腰直角三角形。我们可以预处理出两条对角线上的白点个数。然后枚举一个点,再递增边长,在保证两条等边不含黑点的前提下,通过判断第三条边上的白点个数来判断第三条边上是否含有黑点。

这样的三角形一共有八种。第一类是斜边在对角线上的三角形,可以枚举直角点,再递增边,判断斜边。第二类是斜边在行或列上的三角形,这样可以枚举斜边中点,沿中点递增边,然后判断两条直角边。

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
][];
][];
][],UR[][];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    ; i<=n; ++i)
    {
        scanf();
        ; j<=m; ++j)
            mp[i][j]=(grid[i][j]==:;
    }
    ; i<=n; ++i)
        ; j<=m; ++j)
            UL[i][j]=UL[i-][j-]+mp[i][j];
    ; i<=n; ++i)
        ; --j)
            UR[i][j]=UR[i-][j+]+mp[i][j];
    ;
    ; i<=n; ++i)
        ; j<=m; ++j)
            if(mp[i][j])
            {
                ; mp[i-d][j]&&mp[i][j-d]; ++d) //左上
                    ][j+]==d+)
                        ans++;
                ; mp[i+d][j]&&mp[i][j+d]; ++d)//右下
                    ][j+d+]==d+)
                        ans++;
                ; mp[i-d][j]&&mp[i][j+d]; ++d)//右上
                    ][j-]==d+)
                        ans++;
                ; mp[i+d][j]&&mp[i][j-d]; ++d)//左下
                    ][j-d-]==d+)
                        ans++;
                ; mp[i-d][j]&&mp[i+d][j]; ++d) //左
                    ][j+]==d+&&UL[i+d][j]-UL[i-][j-d-]==d+)
                        ans++;
                ; mp[i+d][j]&&mp[i-d][j]; ++d)//右
                    ][j-]==d+&&UR[i+d][j]-UR[i-][j+d+]==d+)
                        ans++;
                ; mp[i][j-d]&&mp[i][j+d]; ++d) //上
                    ][j+]==d+&&UL[i][j+d]-UL[i-d-][j-]==d+)
                        ans++;
                ; mp[i][j+d]&&mp[i][j-d]; ++d)//下
                    ][j+d+]==d+&&UL[i+d][j]-UL[i-][j-d-]==d+)
                        ans++;
            }
    printf("%d\n",ans);
    ;
}

E。找规律+构造。

答案大致有这么几种情况:

第一类:

1212

3434

1212

3434

或者

1232

3414

1232

1414等等

这类的特点是以左上角的四个格为单元,不断在每列上重复得到。而在每行上,可分为第一、二行交不交换几种情况。

第二类:

1212

3434

2121

3434

或者

1212

3434

2121

4343等等

这类的特点是以左上角的四个格为单元,不断在每行上重复得到。而在每列上,可分为第一、二列交不交换几种情况。

我们需要找出所有情况判断是否和给出的矩阵匹配即可。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
][];
int n,m;
][];
bool judge(int x,int y)
{
    '!=arr[x][y]) return false;
    return true;
}
void output()
{
    ; i<=n; ++i)
    {
        ; j<=m; ++j)
            printf("%d",arr[i][j]);
        printf("\n");
    }
}
bool check1()
{
    ; j<=; ++j)
        ; i<=n; ++i)
        {
            arr[i][j]=arr[i-][j];
            if(!judge(i,j))
                return false;
        }
    ; j<=m; ++j)
    {
        bool ok=true;
        arr[][j]=arr[][j-];
        arr[][j]=arr[][j-];
        ,j)||!judge(,j)) ok=false;
        ; i<=n&&ok; ++i)
        {
            arr[i][j]=arr[i-][j];
            if(!judge(i,j)) ok=false;
        }
        if(ok) continue;
        ok=true;
        arr[][j]=arr[][j-];
        arr[][j]=arr[][j-];
        ,j)||!judge(,j)) ok=false;
        ; i<=n&&ok; ++i)
        {
            arr[i][j]=arr[i-][j];
            if(!judge(i,j))
                ok=false;
        }
        if(!ok) return false;
    }
    return true;
}
bool check2()
{
    ; i<=; ++i)
        ; j<=m; ++j)
        {
            arr[i][j]=arr[i][j-];
            if(!judge(i,j))
                return false;
        }
    ; i<=n; ++i)
    {
        bool ok=true;
        arr[i][]=arr[i-][];
        arr[i][]=arr[i-][];
        )||!judge(i,)) ok=false;
        ; j<=m&&ok; ++j)
        {
            arr[i][j]=arr[i][j-];
            if(!judge(i,j))
                ok=false;
        }
        if(ok) continue;
        arr[i][]=arr[i-][];
        arr[i][]=arr[i-][];
        ok=true;
        )||!judge(i,)) ok=false;
        ; j<=m&&ok; ++j)
        {
            arr[i][j]=arr[i][j-];
            if(!judge(i,j))
                ok=false;
        }
        if(!ok)  return false;
    }
    return true;
}
int main()
{
    scanf("%d%d",&n,&m);
    ; i<=n; ++i)
        scanf();
    ]= {,,,};
    do
    {
        arr[][]=p[];
        arr[][]=p[];
        arr[][]=p[];
        arr[][]=p[];
        bool ok=true;
        ; i<=&&ok; ++i)
            ; j<=&&ok; ++j)
                if(!judge(i,j))ok=false;
        if(!ok) continue;
        if(check1()||check2())
        {
            output();
            ;
        }
    }
    ));
    puts(");
    ;
}

Codeforces Round #249 (Div. 2)的更多相关文章

  1. 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

    题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...

  2. Codeforces Round #249 (Div. 2) C题,模拟画图 ----未解决!

    http://codeforces.com/contest/435/problem/C

  3. Codeforces Round #249 (Div. 2)B(贪心法)

    B. Pasha Maximizes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  4. Codeforces Round #249 (Div. 2) A题

    链接:http://codeforces.com/contest/435/problem/A   A. Queue on Bus Stop time limit per test 1 second m ...

  5. Codeforces Round #249 (Div. 2) D. Special Grid 枚举

    题目链接: http://codeforces.com/contest/435/problem/D D. Special Grid time limit per test:4 secondsmemor ...

  6. Codeforces Round #249 (Div. 2) 总结

    D.E还是很难的.....C不想多说什么... A:提意:给出每一组人的个数,以及一次车载容量,求出最少需要多少次才能载走所有的人. water: http://codeforces.com/cont ...

  7. Codeforces Round #249 (Div. 2) (模拟)

    C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #249 (Div. 2) C. Cardiogram

    C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. Codeforces Round #249 (Div. 2) A. Black Square

    水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...

  10. Codeforces Round #249 (Div. 2) B. Pasha Maximizes

    看到题目的时候,以为类似插入排序,比较第i个元素和第i-1个元素, 如果第i个元素比第i-1个元素小,则不交换 如果第i个元素比第i-1个元素大,则交换第i个元素和第i-1个元素 继续比较第i-1个元 ...

随机推荐

  1. alertdialog.builder 自定义弹窗

    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...

  2. iOS AVAudioRecorder 录音频率、声道、位数配置 wav格式

    iOS AVAudioRecorder 录音频率.声道.位数配置 #pragma mark 录音设置 - (void)setUP_VOICE_RECOARDER { NSError *error = ...

  3. ADO

    目 录 第1章 基础    1 1.1 引入ADO库文件    1 1.1.1 版本    1 1.2 初始化OLE/COM库环境    2 1.3 comdef.h    2 1.3.1 字符串编码 ...

  4. Android Service与Thread的区别

    Android Service,后台,Android的后台就是指,它的运行是完全不依赖UI的.即使Activity被销毁,或者程序被关闭,只要进程还在,Service就可以继续运行.比如说一些应用程序 ...

  5. hdu-----(2807)The Shortest Path(矩阵+Floyd)

    The Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. MFC学习之窗口基础

    WinMain函数 1.句柄(HANDLE):{ 1. 定义:资源的标识 2. 句柄的作用: 操作系统通过句柄来找到对应的资源,从而对这些资源进行管理和操作. 3句柄的分类:(按资源){ 1.图标句柄 ...

  7. Intellij IDEA 安装 Mybatis插件

    1.Ctrl+Alt+s

  8. 初始hibernate(一)

    Hibernate(开放源代码的对象关系映射框架) Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,它将POJO与数据库表建立映射关系,是一个全自动的or ...

  9. javascript function new this

    1. 首先,我们这里把function直接调用时将这个function当做方法来看待,而new function是将function当做类来看待 2. 当把function作为类来使用时,functi ...

  10. 如何用SQL返回两个日期之间的所有连续日期

    在层次查询中,Oracle引入了一个伪列level,用来表示当前行(节点)对应的level, 它从1开始计数,每多一层level的值就加1. 我们可以据此实现对两个日期/整数之间所有日期/整数的遍历. ...