SPOJ AMR12G The Glittering Caves of Aglarond 解题报告
来源:互联网 发布:用dwcs5制作淘宝 编辑:程序博客网 时间:2024/05/20 06:08
题目
Summer Training 06 - Amritapuri 2012 总结
题意:
一些‘.'和'*'组成的矩阵,每次可以翻转一行,使得该行的‘.'和'*'互相转换,求恰好转K次后最多的'*'。
题解:
将行分两类:*比.多的和少的。将少的排序,那么优先翻转使得*增加多的。如果翻完后还没翻够,如果是偶数就相当于不用再翻,否则翻一次使得*减少最少的。
//Time:0ms//Memory:3277KB//Length:1062B#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>using namespace std;#define MAXN 60char str[MAXN][MAXN];int num[2][MAXN],h[2];int main(){ //freopen("/home/moor/Code/input","r",stdin); int ncase,n,m,k,ans=0; scanf("%d",&ncase); while(ncase--) { ans=0; scanf("%d%d%d",&n,&m,&k); for(int i=0;i<n;++i) scanf("%s",str[i]); h[0]=h[1]=0; for(int i=0;i<n;++i) { int cnt=0; for(int j=0;j<m;++j) if(str[i][j]=='*') ++cnt,++ans; if(cnt*2<m) num[0][h[0]++]=cnt; else num[1][h[1]++]=cnt; } sort(num[0],num[0]+h[0]); for(int i=0;i<h[0]&&k;++i,--k) { ans+=m-num[0][i]*2; num[1][h[1]++]=m-num[0][i]; } if(k>0&&k&1) { k=1; sort(num[1],num[1]+h[1]); ans-=2*num[1][0]-m; } printf("%d\n",ans); } return 0;}
- SPOJ AMR12G The Glittering Caves of Aglarond 解题报告
- UVALive 6345 The Glittering Caves of Aglarond (找规律求最多)
- SPOJ AMR12K The Loyalty of the Orcs 解题报告
- SPOJ AMR12D The Mirror of Galadriel 解题报告
- SPOJ AMR12A The Black Riders 解题报告
- 解题报告:SPOJ
- SPOJ AMR12I Saruman of Many Colours 解题报告
- SPOJ AMR12B Gandalf vs the Balrog 解题报告
- SPOJ AMR12J Escape from the Mines 解题报告
- 【解题报告】hdu1010 Tempter of the Bone
- hdoj1010(temper of the bone) 解题报告
- Spoj数论专场解题报告
- SPOJ AMR12C Entmoot 解题报告
- 解题报告 之 HDU5318 The Goddess Of The Moon
- HDU 1010 Tempter of the Bone 解题报告
- HDOJ 1010 Tempter of the Bone解题报告
- HDOJ 1010:Tempter of the Bone 迷宫问题 解题报告
- POJ-3083 Children of the Candy Corn 解题报告
- TCP演进简述
- 彻底解决asp.net mvc 3 404错误码返回302的问题
- HDU 1016 Prime Ring Problem【DFS】
- Linux--13:ubuntu下如何用命令行运行deb安装包
- matlab稀疏矩阵处理
- SPOJ AMR12G The Glittering Caves of Aglarond 解题报告
- LeetCode-Spiral Matrix
- POJ 1320 Street Number(佩尔方程)
- uva 193 Graph Coloring(DFS)
- Android升级ADT22后会报ClassNotFoundException的原因分析
- C实现的循环链表排序
- 解决:Failed to fectch URl https://dl-ssl.google.com/android/repository/addons_list.xml, reason: Connec
- UNIX网络编程——揭开网络编程常见API的面纱【下】
- 获取新浪天气预报的功能