UVALive 6345 The Glittering Caves of Aglarond (找规律求最多)
发布日期:2021-11-06 16:56:36 浏览次数:6 分类:技术文章

本文共 2957 字,大约阅读时间需要 9 分钟。

The Glittering Caves of Aglarond
Time Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu

Description

'Strange are the ways of Men, Legolas! Here they have one of the marvels of the Northern World, and what do they say of it? Caves, they say! Caves! Holes to fly to in time of war, to store fodder in! My good Legolas, do you know that the caverns of Helm's Deep are vast and beautiful? There would be an endless pilgrimage of Dwarves, merely to gaze at them, if such things were known to be. Aye indeed, they would pay pure gold for a brief glance!

'And, Legolas, when the torches are kindled and men walk on the sandy floors under the echoing domes, ah! then, Legolas, gems and crystals and veins of precious ore glint in the polished walls; and the light glows through folded marbles, shell-like, translucent as the living hands of Queen Galadriel.'
- Gimli, describing to Legolas the Glittering Caves of Aglarond.

While these caves are by and large natural, there is one place where the Men of Rohan have chiseled into the rock to create a magnificent exhibit. You have a wall of the cave consisting of 'lighted diamonds' arranged in a N by M grid (basically, you have a light behind each diamond which can be turned on or off). Further, you have a switch corresponding to each row of this diamond-grid. When you operate a switch, it will toggle (flip) the lights corresponding to that row.

You are given the current configuration of the lighted diamonds. Gimli challenges Legolas to turn on as many diamonds as possible using EXACTLY K on/off operations of the switches. Since Legolas is an Elf of the Wood and doesn't care much for things that glitter, he instead asks for your help. Note that the same switch (i.e. row) can be chosen multiple times.

Input

The first line contains the number of test cases T.

Each test case contains N, M and K on the first line followed by N lines containing M characters each. The i-th line denotes the state of the diamonds in the i-th row, where '*' denotes a diamond which is on and '.' denotes a diamond which is off.

Output

Output T lines containing the answer for the corresponding case.

Between successive test cases, there should not be any blank lines in the output.

Constraints:
1<=T<=100
1<=N, M<=50
1<=K<=100

Notes/Explanation of Sample Input:

In the first test case, row 1 can be toggled hence leaving all 4 lights to be in the ON state.

In the second test case, row 1 (or row 2) can be toggled twice, hence maintaining the state of the initial configuration.

Sample Input

22 2 1..**2 2 2..**

Sample Output

42
AC代码:

#include 
#include
#include
using namespace std;//author:XXYYbool cmp(int a,int b){ return a>b;}int main(){ int t,n,m,k,i,count,j; int num,l1,l2,b[55],c[55]; char a[55][55]; scanf("%d",&t); while(t--){ count=0; l1=l2=0; scanf("%d%d%d",&n,&m,&k); for(i=0;i
0) b[l1++]=m-2*num; else c[l2++]=2*num-m; } sort(b,b+l1,cmp); for(i=0;i

转载地址:https://blog.csdn.net/YJX_xx/article/details/37363341 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Codeforces Round #254 (Div. 2)445A DZY Loves Chessboard(字符串处理)
下一篇:UVALive 6342 The Mirror of Galadriel (回文串)

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月14日 14时03分42秒