OUC_TeamTraining_#1 720
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.
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 ;
}
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.
#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的更多相关文章
- VR全景智慧城市-720全景项目行业应用
VR虚拟现实.VR全景概念已成为科技发展热议的焦点.在这样的市场大环境下,全景智慧城市做为一家对大众创新万众创业和用户体验为理念的VR全景城市化信息搜素平台平地而生成为的VR行业领跑者,致力VR全景V ...
- 2014年最新720多套Android源码2.0GB免费一次性打包下载
之前发过一个帖子,但是那个帖子有点问题我就重新发一个吧,下面的源码是我从今年3月份开始不断整理源码区和其他网站上的android源码,目前总共有720套左右,根据实现的功能被我分成了100多个类,总共 ...
- VR全景加盟、720全景、VR全景技术平台-全国招商模式疯狂开始
VR全景:互联网与实体店的完美结合 VR元年已过,VR项目.VR创业潮转为理性,VR行业分为两个方向:硬件和内容.硬件又分为VR头显和辅助设备,内容又分为VR全景和VR虚拟内容,如游戏.娱乐.根据行 ...
- win10连接宽带,拨号提示错误720:不能建立到远程计算机的连接,解决方法
使用账号密码登录时,一直报720错误.解决方法是卸载以下IP驱动.卸载之后重新连接就正常了.亲测有效
- win10 校园宽带连接不上的解决办法(错误720、“以太网”没有有效的ip设置)
遇到的问题如下图所示: 插上宽带后,查看以太网状态显示如下: 创建新连接宽带(PPPoE)(R)后,连接失败,错误为720,显示如下: 以太网网络诊断后,结果显示“以太网”没有有效的Ip设置,如下图所 ...
- AOJ.720 丢失的学妹
缺失的学妹 考察点 STL MAP Time Mem Len Lang 3.81s 39.1MB 0.68K G++ 题意分析 给出妹子学号的个数n,给出n个学号,和n-1个学号,求在n学号中那个没有 ...
- PCB 720全景图嵌入登入界面应用实现
通常软件主界面或登入界面背景图片通常采用固定图片,这里介绍如何将720度全景图嵌入到登入界面中来, 这里用的素材来源于这里上个月在公司里拍摄的全景图, 一.拍摄720度全景图片, 建议:最好用三角固定 ...
- 【Leetcode_easy】720. Longest Word in Dictionary
problem 720. Longest Word in Dictionary 题意: solution1: BFS; class Solution { public: string longestW ...
- PTA数据结构与算法题目集(中文) 7-20
PTA数据结构与算法题目集(中文) 7-20 7-20 表达式转换 (25 分) 算术表达式有前缀表示法.中缀表示法和后缀表示法等形式.日常使用的算术表达式是采用中缀表示法,即二元运算符位于两个 ...
随机推荐
- MVC全局过滤器
Asp.NET MVC4中的全局过滤器,可以对整个项目进行全局监控. 新建一个MVC4项目,可以在global.asax文件中看到如下代码: FilterConfig.RegisterGlobalF ...
- IOC之MEF学习
MEF原理上很简单,找出有共同接口的导入.导出.然后找到把导出的实例化,赋给导入.说到底MEF就是找到合适的类实例化,把它交给导入.Export 特性可修饰类.字段.属性或方法,而 Import 特性 ...
- 小知识:修改IDEA的模板
小知识:修改IDEA的模板 有时候我们会发现,IDEA默认创建的模板并不是我们常用的.与其每次都在创建后进行修改,不如直接对模板进行修改. 给不知道怎么修改的同学指一下路: File->sett ...
- 用表格制作商品购买页面--(table)
实现效果如图: 首先来看布局,头部图片,内容从左到右分为四个部分 勾选+商品图片+商品名/买家+价格, 所以需要将头部用<td>包括起来,并且设置<td colspan=&quo ...
- JS-实现横向手风琴
横向手风琴-- 鼠标悬浮某一张图片,图片显示,其他图片影藏. <div class="content"> <ul> <li class="c ...
- body测试onclick等鼠标事件无效果详解
DOM事件机制包括五部分: DOM事件级别 DOM事件流 DOM事件模型 事件代理 Event对象常见的方法和属性 但是有时候发现给body标签里设置onclick属性,不起作用,代码如下: 不管单击 ...
- Linux学习(二)-Xshell 5和Xftp 5的安装和使用
(一)软件介绍: (1)Xshell: Xshell通过互联网可以连接到远程的服务器,然后通过模拟终端来实现对服务器的各种操作,而且这款软件可以很好的解决中文乱码问题,非常的方便快捷. (2)Xftp ...
- 说说css hack,说真的,我也是才去了解这个东西
之前在很多地方看到css hack,今天狠下心,看看到底是什么鬼,所有我去百度了,然后看了一篇文章,然后写个小总结. css hack就是通过加一些特定的符号,不同的浏览器可以识别特定符号的样式,以此 ...
- 第一篇.markdown
目录 Day 01 1.markdown的使用感受 2.markdown的基本语法 2.1 标题 2.2 加粗 2.3 斜体 2.4 高亮 2.5 上标 2.6 下标 2.7 代码引用(>式) ...
- 解读Position
首先Position在字面讲是位置的意思,在HTML中是定位的意思,它有四种属性:分别是static是静态的,也是默认的效果,没有特别的设定,遵循基本的定位规定,不能通过z-index进行层次分级. ...