D - The Mirror of Galadriel

Time Limit:2000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

With water from the stream Galadriel filled the basin to the brim, and breathed on it, and when the water was still again she spoke. 'Here is the Mirror of Galadriel,' she said. 'I have brought you here so that you may look in it, if you will. For this is what your folk would call magic, I believe; though I do not understand clearly what they mean; and they seem also to use the same word of the deceits of the Enemy. But this, if you will, is the magic of Galadriel. Did you not say that you wished to see Elf-magic?' - Galadriel to Frodo and Sam, describing her Mirror.
We call a string S magical if every substring of S appears in Galadriel's Mirror (under lateral inversion). In other words, a magical string is a string where every substring has its reverse in the string.
Given a string S, determine if it is magical or not.
Input (STDIN):
The first line contains T, the number of test cases. The next T lines contain a string each. 
Output (STDOUT):
For each test case, output "YES" if the string is magical, and "NO" otherwise.
Constraints:
1 <= T <= 100
1 <= |S| <= 10
S contains only lower-case characters.
Time Limit: 1s
Memory Limit: 64MB
Sample Input:
2
aba
ab
Sample Output:
YES
NO
Notes/Explanation of Sample Input:
For the first test case, the list of substrings are : a, b, ab, ba, aba. The reverse of each of these strings is present as a substring of S too.
For the second test case, the list of substring are : a, b, ab. The reverse of "ab", which is "ba" is not present as a substring of the string.

With water from the stream Galadriel filled the basin to the brim, and breathed on it, and when the water was still again she spoke. 'Here is the Mirror of Galadriel,' she said. 'I have brought you here so that you may look in it, if you will. For this is what your folk would call magic, I believe; though I do not understand clearly what they mean; and they seem also to use the same word of the deceits of the Enemy. But this, if you will, is the magic of Galadriel. Did you not say that you wished to see Elf-magic?' - Galadriel to Frodo and Sam, describing her Mirror.

We call a string S magical if every substring of S appears in Galadriel's Mirror (under lateral inversion). In other words, a magical string is a string where every substring has its reverse in the string.

Given a string S, determine if it is magical or not.

Input (STDIN):

The first line contains T, the number of test cases. The next T lines contain a string each.

Output (STDOUT):

For each test case, output "YES" if the string is magical, and "NO" otherwise.

Constraints:

1 <= T <= 100

1 <= |S| <= 10

S contains only lower-case characters.

Sample Input:

2

aba

ab

Sample Output:

YES

NO

Notes/Explanation of Sample Input:

For the first test case, the list of substrings are : a, b, ab, ba, aba. The reverse of each of these strings is present as a substring of S too.

For the second test case, the list of substring are : a, b, ab. The reverse of "ab", which is "ba" is not present as a substring of the string.

一个字符串的所有子串倒序后还是该字符串的子串。(规律就是这个字符串是对称的。)

 #include<stdio.h>
#include<string.h>
char str[];
char str2[];
int main()
{
int t;
int len;
scanf("%d",&t);
while(t--)
{
scanf("%s",str);
len = strlen(str);
int i = ,j = len-;
for(;i < len;i++,j--)
{
str2[j] = str[i];
}
if(strcmp(str,str2) == )
printf("YES\n");
else
printf("NO\n");
memset(str,'\0',);
memset(str2,'\0',);
len = ;
}
return ;
}
G - The Glittering Caves of Aglarond

Time Limit:2000MS     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 (STDIN):

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 ith line denotes the state of the diamonds in the ith row, where '*' denotes a diamond which is on and '.' denotes a diamond which is off.

Output (STDOUT):

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

Sample Input:

2

2 2 1

..

**

2 2 2

..

**

Sample Output:

4

2

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.

 题意是 有N行M列个钻石,每一个钻石后面都有一个灯,初始状态不一定。有开关进行操作,但是一次操作就是一行钻石,(开就变成关,关就变成开),必须有K次操作,输出进行完操作后,亮着的钻石个数的最大值。
方法:记录每一行亮灯的个数,每次只操作亮灯最少的那一行。
 #include<stdio.h>
#include<string.h>
char D[][];
int l[] = {};
int Min(int l[],int n)
{
int i,min = l[],j = ;
for(i = ;i < n;i++)
{
if(min > l[i])
{
min = l[i];
j = i;
}
}
return j;
}
int main()
{
int T,M,N,K,min = ;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&N,&M,&K);
getchar();
int i,j; for(i = ;i < N;i++)
{
for(j = ;j <M;j++)
{
scanf("%c",&D[i][j]);
if(D[i][j] == '*')l[i]++;
}
getchar();
} while(K--)
{
min = Min(l,N);
l[min] = M - l[min];
}
int sum = ;
for(i = ;i < N;i++)
{
sum += l[i];
}
printf("%d\n",sum);
memset(l,,sizeof(l));
}
return ;
}

下面这道题一直交不对不知道是不是理解题错了。

G - The Glittering Caves of Aglarond

Time Limit:2000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit     Status       Practice        SPOJ AMR12G

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 i? 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 (STDIN):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 ith line denotes the state of the diamonds in the ith row, where '*' denotes a diamond which is on and '.' denotes a diamond which is off.Output (STDOUT):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 <= 1001 <= N,M <= 501 <= K <= 100Sample Input:22 2 1..**2 2 2..**Sample Output:42Notes/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.

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 (STDIN):

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 ith line denotes the state of the diamonds in the ith row, where '*' denotes a diamond which is on and '.' denotes a diamond which is off.

Output (STDOUT):

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

Sample Input:

2

2 2 1

..

**

2 2 2

..

**

Sample Output:

4

2

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.

题目的意思应该是有一队士兵要被涂上颜色,每次必须涂K个士兵,传送带可以向前走可以向后走。给出规定的颜色,如果能被涂出颜色 输出最少要涂色的次数 如果不能 输出-1

我是这样想的,要是能被涂好颜色必须 前K个或后K个是一样的颜色,否则不行。如果前K个不一样后K个一样传送带从前向后走,如果前K个一样后K个不一样 传送带从后向前走,如果两边都能走,则从前向后,从后向前结果应该是一样的。这里还有一个问题是,不会存在传送带一会向前一会向后的情况,那样就没有意义了。所以在一开始就要确定方向就好了。然后传送带在走的过程中每次处理K个士兵,先都涂上K个中第一个的颜色,不符合要求的留下来再涂。写成代码就是如果前后不一样就要加1如果一样集齐K个后就要加1.

但是交了就是不对 好懊恼 要是有路过的大神求指点~~

 #include<stdio.h>
#include<string.h>
char D[][];
int l[] = {};
int Min(int l[],int n)
{
int i,min = l[],j = ;
for(i = ;i < n;i++)
{
if(min > l[i])
{
min = l[i];
j = i;
}
}
return j;
}
int main()
{
int T,M,N,K,min = ;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&N,&M,&K);
getchar();
int i,j; for(i = ;i < N;i++)
{
for(j = ;j <M;j++)
{
scanf("%c",&D[i][j]);
if(D[i][j] == '*')l[i]++;
}
getchar();
} while(K--)
{
min = Min(l,N);
l[min] = M - l[min];
}
int sum = ;
for(i = ;i < N;i++)
{
sum += l[i];
}
printf("%d\n",sum);
memset(l,,sizeof(l));
}
return ;
}

编译器太难用了颜色什么的忽略吧 凑活看吧

OUC_TeamTraining_#1 720的更多相关文章

  1. VR全景智慧城市-720全景项目行业应用

    VR虚拟现实.VR全景概念已成为科技发展热议的焦点.在这样的市场大环境下,全景智慧城市做为一家对大众创新万众创业和用户体验为理念的VR全景城市化信息搜素平台平地而生成为的VR行业领跑者,致力VR全景V ...

  2. 2014年最新720多套Android源码2.0GB免费一次性打包下载

    之前发过一个帖子,但是那个帖子有点问题我就重新发一个吧,下面的源码是我从今年3月份开始不断整理源码区和其他网站上的android源码,目前总共有720套左右,根据实现的功能被我分成了100多个类,总共 ...

  3. VR全景加盟、720全景、VR全景技术平台-全国招商模式疯狂开始

    VR全景:互联网与实体店的完美结合  VR元年已过,VR项目.VR创业潮转为理性,VR行业分为两个方向:硬件和内容.硬件又分为VR头显和辅助设备,内容又分为VR全景和VR虚拟内容,如游戏.娱乐.根据行 ...

  4. win10连接宽带,拨号提示错误720:不能建立到远程计算机的连接,解决方法

    使用账号密码登录时,一直报720错误.解决方法是卸载以下IP驱动.卸载之后重新连接就正常了.亲测有效

  5. win10 校园宽带连接不上的解决办法(错误720、“以太网”没有有效的ip设置)

    遇到的问题如下图所示: 插上宽带后,查看以太网状态显示如下: 创建新连接宽带(PPPoE)(R)后,连接失败,错误为720,显示如下: 以太网网络诊断后,结果显示“以太网”没有有效的Ip设置,如下图所 ...

  6. AOJ.720 丢失的学妹

    缺失的学妹 考察点 STL MAP Time Mem Len Lang 3.81s 39.1MB 0.68K G++ 题意分析 给出妹子学号的个数n,给出n个学号,和n-1个学号,求在n学号中那个没有 ...

  7. PCB 720全景图嵌入登入界面应用实现

    通常软件主界面或登入界面背景图片通常采用固定图片,这里介绍如何将720度全景图嵌入到登入界面中来, 这里用的素材来源于这里上个月在公司里拍摄的全景图, 一.拍摄720度全景图片, 建议:最好用三角固定 ...

  8. 【Leetcode_easy】720. Longest Word in Dictionary

    problem 720. Longest Word in Dictionary 题意: solution1: BFS; class Solution { public: string longestW ...

  9. PTA数据结构与算法题目集(中文) 7-20

    PTA数据结构与算法题目集(中文)  7-20 7-20 表达式转换 (25 分)   算术表达式有前缀表示法.中缀表示法和后缀表示法等形式.日常使用的算术表达式是采用中缀表示法,即二元运算符位于两个 ...

随机推荐

  1. [转载]torch参数:torch.backends.cudnn.benchmark的意义

    [转载]torch参数:torch.backends.cudnn.benchmark的意义 来源:https://zhuanlan.zhihu.com/p/73711222 完整版请看原文,这里只截取 ...

  2. YOLO 学习之路

    参考自官网  https://pjreddie.com/darknet/install/ 1. 下载darknet  并编译 git clone https://github.com/pjreddie ...

  3. gogs 搭建

    sudo apt-get install nginx sudo apt-get install git sudo apt-get install mysql-server mysql -u root ...

  4. Java秒杀实战 (六) 服务级高并发秒杀优化(RabbitMQ+接口优化)

    转自:https://blog.csdn.net/qq_41305266/article/details/81146716 一.思路:减少数据库访问 1.系统初始化,把商品库存数量加载到Redis 2 ...

  5. SAP云平台里Global Account和Sub Account的关系

    在Cloud Foundry环境里,一个Global Account或者Trial Account能够创建多个SubAccount,如图: 创建好的新的subaccount: 一旦subaccount ...

  6. css 之引入自定义字体/特殊字体-----使用ttf格式语言包

    1.准备好需要的 .ttf 格式的语言包,在css导入: @font-face { font-family: myFont; src: url('../assets/font/Oswald-SemiB ...

  7. Django安装和介绍

    在CMD和pycharm的安装方法. 先说CMD的安装方法 1,使用pip3 install django 2,进入c:python\Scripts 3,django-admin.exe startp ...

  8. STM32——CAN协议帧的标准格式和扩展格式与优先级的关系

    一.CAN数据帧的标准格式和扩展格式 我们知道CAN总线上的数据帧都可以配置一个ID号,其可以为11位(标准ID格式)或者29位(扩展ID格式),这也是数据帧的标准格式和扩展格式的区别所在. 这个ID ...

  9. Django:forms局部函数、cookie、sesion、auth模块

    一.forms组件 二.cookie和session组件 三.auth组件 一.forms组件 1.校验字段功能 针对一个实例:注册用户讲解 模型:models class UserInfo(mode ...

  10. 5.caffe图片分类流程

    一次创建下列文件: 1,create_txt.sh (create_filelist.sh) 2,create_lmdb.sh 3,make_mean.sh 4,train.prototxt+val. ...