zoukankan      html  css  js  c++  java
  • hdu 4708(暴力+找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708

    思路:由于N不大,并且我们可以发现通过旋转得到的4个对角线的点的位置关系,以及所要旋转的最小步数,然后把所有的符合条件的都加入数组中,最后排序即得。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 struct Node{
     8     int sum,step;
     9 }node[11][11],ans[11][11];
    10 
    11 int n,p,k;
    12 int map[11][11];
    13 
    14 int cmp(const Node &p,const Node &q)
    15 {
    16     if(p.sum!=q.sum){
    17         return p.sum>q.sum;
    18     }
    19     return p.step<q.step;
    20 }
    21 
    22 int main()
    23 {
    24     while(~scanf("%d",&n)&&n){
    25         for(int i=1;i<=n;i++)
    26             for(int j=1;j<=n;j++)
    27                 scanf("%d",&map[i][j]);
    28         p=k=0;
    29         for(int i=1;i<=n/2;i++){
    30             p++;
    31             k=0;
    32             for(int j=i;j<=n-i;j++){
    33                 node[p][k].sum=map[i][j]+map[n-i+1][n-j+1]+map[j][n-i+1]+map[n-j+1][i];
    34                 node[p][k].step=min(j-i,n-i+1-j);
    35             //    cout<<node[p][k].sum<<endl;
    36                 k++;    
    37             }
    38             sort(node[p],node[p]+k,cmp);
    39         //    for(int i=0;i<k;i++)cout<<node[p][i].sum<<"**"<<node[p][i].step<<endl;
    40         }
    41         int ans1=0,ans2=0;
    42         for(int i=1;i<=p;i++){
    43             ans1+=node[i][0].sum;
    44             ans2+=node[i][0].step;
    45         }
    46         printf("%d %d
    ",ans1+map[n/2+1][n/2+1],ans2);
    47     }
    48     return 0;
    49 }
    50             
    View Code
  • 相关阅读:
    搭建zabbix监控
    liunx 下ctrl+D问题解决方案
    linux配置双线策略
    Discuz! X2.5读写分离
    慢谈MYSQL常用SQL语句
    CentOS 6.5系统安装配置LAMP(Apache+PHP5+MySQL)服务器环境
    自动抓包shell脚本
    zabbix实施部署原理架构
    ftp搭建教程
    DNS搭建教程
  • 原文地址:https://www.cnblogs.com/wally/p/3308701.html
Copyright © 2011-2022 走看看