T1

【题目描述】

给你N个字符串,你每次可以选择其中一个字符串的一段前缀进行翻转,但是你必须保证这个前缀的长度是偶数。你可以进行无限次这样的操作,并且如果
两个字符串变得相同的时候,你就可以把这两个字符串都删除掉,问最后最少剩下多少个字符串?

【输出格式】
对于每组数据,一行一个整数代表答案。
【样例输入】
2
5
esprit
god
redotopc
odcpoter
dog
14
rats
live
stressed
to
act
as
star
desserts
of
evil
cat
sa
fo
ot

【样例输出】
3
0
【样例解释】
无。
【数据范围与规定】

对于40%的数据,字符串长度不超过8

对于100%的数据,1<=T<=11,字符串长度不超过50,1<=N<=50

#include <cstdio>
#include <cstring>
char s[][];
int t,n,ans,len[];
bool vis[][],del[]; inline void work(int x)
{
len[x]=strlen(s[x]);
--len[x];//长度若是单数,那么下面枚举到最后时会出现vis[负数]=true
for(int i=;i<len[x];i+=)
vis[x][s[x][i]-'a'+s[x][i+]-'a']=true;
++len[x];
} inline bool judge(int i,int j)
{
for(int k=;k<;++k)
if(vis[i][k]!=vis[j][k])
return false;
// printf("\n%s %s\n",s[i],s[j]);
if(len[i]&)
return s[i][len[i]-]==s[j][len[j]-];
return true;
} inline void clear()
{
ans=;
memset(vis,false,sizeof vis);
memset(del,false,sizeof del);
} int main()
{
freopen("kahuucino.in","r",stdin);
freopen("kahuucino.out","w",stdout);
scanf("%d",&t);
while(t--)
{
clear(); scanf("%d",&n);
for(int i=;i<=n;++i)
scanf("%s",s[i]); for(int i=;i<=n;++i)
work(i);//处理每个字符串的情况 /*
printf("\n");
for(int i=1;i<=n;++i)
printf("%d ",len[i]);
printf("\n");
*/ for(int l,i=;i<=n;++i)
{
if(del[i])continue;
for(int j=i+;j<=n;++j)
{
if(del[j]||len[i]!=len[j])continue;
if(judge(i,j))
{
// printf("\n%d %d\n",i,j);
del[j]=true;
ans+=;
break;
}
}
}
printf("%d\n",n-ans);
}
fclose(stdin);fclose(stdout);
return ;
}
/*
5
esprit
god
redotopc
odcpoter
dog 样例第一组数据解释:
redotopc -> cpot oder -> topcod er -> do cpoter -> odcpoter
最后剩3个 以连续两个字符为一个单位
*/

考试30分代码

/*
把字符串拆成有两个字母的组合
然后将这些组合按照字典序排起来,合到一起形成一个新的字符串
最后判断这个字符串有没有出现过
*/
#include <algorithm>
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <set> std::set<std::string> h;
std::string a[];
int getMin(std::vector<std::string> words)
{
int n=words.size(),ans=n;
h.clear();
for(int i=;i<n;++i)
{
int m=words[i].size();
std::string s="";
for (int j=;j*<m;++j)
{
char x=words[i][j*],y=words[i][j*+];
if(x>y)std::swap(x,y);
a[j]=x,a[j]+=y;
}
std::sort(a,a+m/);
for(int j=;j*<m;++j)s+=a[j];
if(m&)s+=words[i][m-];
if(h.find(s)==h.end())h.insert(s);
else h.erase(s),ans-=;
}
return ans;
} int main()
{
freopen("kahuucino.in","r",stdin);
freopen("kahuucino.out","w",stdout); int T,n,m;
std::string s;
std::vector<std::string> w;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
w.clear();
for(int i=;i<n;++i)
{
std::cin>>s;
w.push_back(s);
}
printf("%d\n",getMin(w));
}
fclose(stdin);fclose(stdout);
return ;
}

正解

T2

麻耶
【问题描述】
油库里是幻想乡特有的一种生物。每只油库里都有一个战斗力值和一个能量值。当两只油库里战斗时,总是战斗力值高的一位获胜。获胜者的战斗力值将变成(自己的原战斗力值-对手的战斗力值+对手的能量值)。败者将死去。若两者战斗力值一样,则同归于尽。
思考熊发现了很多油库里,他想知道通过互相战斗之后油库里中战斗力值+能量值最高的一个可能到达多少。你能帮他们求出来吗?

(假设除了考察的那只油库里之外,其他油库里之间不会发生战斗)

【输入格式】
第一行是一个整数N,代表当前有多少油库里。
接下来的N行, 每一行有两个整数u,v, 代表这只油库里的战斗力值和能量值。

【输出格式】
输出一个整数,代表油库里中战斗力值+能量值最高的一个能达到多少。

【样例输入】
2
1 2
2 1
【样例输出】
4
【样例解释】
无。

不是所有油库里都要打一遍!!!

本来自信满满能拿10分……………………

正解是贪心

题意描述不清……

以为是所有油库里都要打一遍

但是实际是可以随意选着搞,想和哪个打和哪个打……

#include <algorithm>
#include <complex>
#include <cstdio>
const int N=1e5+;
#ifdef Win32
#define LL "%I64d"
#else
#define LL "%lld"
#endif
struct node{
int u,v;
}peo[N];
int n;
long long ans;
int read()
{
int n=,w=;register char c=getchar();
while(c<''||c>''){if(c=='-')w=-;c=getchar();}
while(c>=''&&c<='')n=n*+c-'',c=getchar();
return n*w;
}
bool cmp(const node &a,const node &b)
{
if(a.u==b.u)return a.v>b.v;
return a.u<b.u;
}
inline long long max(long long x,long long y)
{return x>y?x:y;}
int main()
{
freopen("zyougamaya.in","r",stdin);
freopen("zyougamaya.out","w",stdout);
n=read();
for(int i=;i<=n;++i)
{
peo[i].u=read();
peo[i].v=read();
ans=max(ans,(long long)peo[i].u+peo[i].v);
}
std::sort(peo+,peo+n+,cmp);
long long sum=;
for(int i=;i<=n;++i)
{
ans=max(ans,sum+peo[i].u+peo[i].v);
if(peo[i].u<peo[i].v)
sum+=peo[i].v-peo[i].u;
}
printf("%I64d",ans);//不能用define的LL,只能得10分
fclose(stdin);fclose(stdout);
return ;
}

正解

T3

思路:大模拟

注意细节!!!!!

#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
char cmd[];
struct Node{
int son[],now,fa,type;
//儿子有哪些,现在到了第几个儿子,父亲是谁,是文件还是文件夹(1是文件,2是文件夹)
std::string s;
Node(){now=,fa=;}
}a[]; inline void del_file(int x)
{
a[x].fa=;
a[x].type=;
a[x].s=' ';
} void del_directory(int x)
{
a[x].fa=;
a[x].s=' ';
a[x].type=;
for(int i=;i<=a[x].now;++i)
{
if(a[a[x].son[i]].type==)
del_file(a[x].son[i]);
else del_directory(a[x].son[i]);
a[x].son[i]=;
}
a[x].now=;
} int main()
{
freopen("nacumegu.in","r",stdin);
freopen("nacumegu.out","w",stdout);
int n,now=-;//now:现在在哪个里面
scanf("%d",&n);
for(int i=;i<=n;++i)
{
// printf("\nGG\n");
scanf("%s",cmd);
switch(cmd[])
{
case 'c'://转换目录
std::cin>>a[i].s; if(a[i].s[]=='.')
{//向上一级
if(a[now].fa!=)
now=a[now].fa;
else printf("No parent directory!\n");
}
else
{//向下一级
for(int j=;j<=a[now].now;++j)
if(a[a[now].son[j]].s==a[i].s&&a[a[now].son[j]].type==)
{
now=a[now].son[j];
goto S;
}
printf("No such directory!\n");
}
// --i,--n;//没必要
continue; case 't'://新建文件 std::cin>>a[i].s;
for(int j=;j<=a[now].now;++j)
if(a[a[now].son[j]].s==a[i].s&&a[a[now].son[j]].type==)
{//已经有了
printf("File already exists!\n");
goto S;
}
a[now].son[++a[now].now]=i;
a[i].now=;
a[i].fa=now;
a[i].type=;
continue; case 'r'://删除 std::cin>>a[i].s;
if(strlen(cmd)<)
{//删除文件
for(int j=;j<=a[now].now;++j)
if(a[a[now].son[j]].s==a[i].s&&a[a[now].son[j]].type==)
{//有
del_file(a[now].son[j]);
a[now].son[j]=;
goto S;
}
printf("No such file!\n");
}
else
{//删除文件夹
for(int j=;j<=a[now].now;++j)
if(a[a[now].son[j]].s==a[i].s&&a[a[now].son[j]].type==)
{//有
del_directory(a[now].son[j]);
a[now].son[j]=;
goto S;
}
printf("No such directory!\n");
}
goto S; case 'm':
//新建文件夹
std::cin>>a[i].s;
for(int j=;j<=a[now].now;++j)
if(a[a[now].son[j]].s==a[i].s&&a[a[now].son[j]].type==)
{//已经有了
printf("Directory already exists!\n");
goto S;
}
a[now].son[++a[now].now]=i;
a[i].now=;
a[i].fa=now;
a[i].type=;
continue; case 'l'://输出目录下的文件及文件夹
for(int j=;j<=a[now].now;++j)
{
if(a[a[now].son[j]].s[]==' ')continue;
std::cout<<a[a[now].son[j]].s;
if(a[a[now].son[j]].type==)
printf(" <F>\n");
else printf(" <D>\n");
}
}
S: ;
}
fclose(stdin);fclose(stdout);
return ;
}

正解

钟长者P71解题报告的更多相关文章

  1. CH Round #56 - 国庆节欢乐赛解题报告

    最近CH上的比赛很多,在此会全部写出解题报告,与大家交流一下解题方法与技巧. T1 魔幻森林 描述 Cortana来到了一片魔幻森林,这片森林可以被视作一个N*M的矩阵,矩阵中的每个位置上都长着一棵树 ...

  2. 二模13day1解题报告

    二模13day1解题报告 T1.发射站(station) N个发射站,每个发射站有高度hi,发射信号强度vi,每个发射站的信号只会被左和右第一个比他高的收到.现在求收到信号最强的发射站. 我用了时间复 ...

  3. BZOJ 1051 最受欢迎的牛 解题报告

    题目直接摆在这里! 1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4438  Solved: 2353[S ...

  4. 习题:codevs 2822 爱在心中 解题报告

    这次的解题报告是有关tarjan算法的一道思维量比较大的题目(真的是原创文章,希望管理员不要再把文章移出首页). 这道题蒟蒻以前做过,但是今天由于要复习tarjan算法,于是就看到codevs分类强联 ...

  5. 习题:codevs 1035 火车停留解题报告

    本蒟蒻又来写解题报告了.这次的题目是codevs 1035 火车停留. 题目大意就是给m个火车的到达时间.停留时间和车载货物的价值,车站有n个车道,而火车停留一次车站就会从车载货物价值中获得1%的利润 ...

  6. 习题: codevs 2492 上帝造题的七分钟2 解题报告

    这道题是受到大犇MagHSK的启发我才得以想出来的,蒟蒻觉得自己的代码跟MagHSK大犇的代码完全比不上,所以这里蒟蒻就套用了MagHSK大犇的代码(大家可以关注下我的博客,友情链接就是大犇MagHS ...

  7. 习题:codevs 1519 过路费 解题报告

    今天拿了这道题目练练手,感觉自己代码能力又增强了不少: 我的思路跟别人可能不一样. 首先我们很容易就能看出,我们需要的边就是最小生成树算法kruskal算法求出来的边,其余的边都可以删掉,于是就有了这 ...

  8. NOIP2016提高组解题报告

    NOIP2016提高组解题报告 更正:NOIP day1 T2天天爱跑步 解题思路见代码. NOIP2016代码整合

  9. LeetCode 解题报告索引

    最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中......                        ...

随机推荐

  1. 【leetcode-91 动态规划】 解码方法

    一条包含字母 A-Z 的消息通过以下方式进行了编码: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 给定一个只包含数字的非空字符串,请计算解码方法的总数. 示例 1 ...

  2. nmon2influxdb+grafana:服务监控可视化部署

    在工作中,无论是定位线上问题,还是性能优化,都需要对前端.后台服务进行监控.而及时的获取监控数据,能更好的帮助技术人员排查定位问题. 前面的博客介绍过服务端监控工具:Nmon使用方法及利用easyNm ...

  3. 在Visual Studio 2019中安装Blend 4.5 SDK

    Visual Studio 2017安装时可以指定Blend SDK,到Visual Studio 2019时,安装时已经没有这个选项了. 官方提供的只有老版本4.0的安装包.要使用Blend SDK ...

  4. tf.reduce_max的运用

    a=np.array([[[[1],[2],[3]],[[4],[25],[6]]],[[[27],[8],[99]],[[10],[11],[12]]],[[[13],[14],[15]],[[16 ...

  5. 数组中[::-1]或[::-n]的区别,如三维数组[:,::-1,:]

    import numpy as npa=np.array([[11,12,13,14,15,16,17,18],[21,22,23,24,25,26,27,28],[31,32,33,34,35,36 ...

  6. eclipse中启动tomcat后, 无法访问localhost:8080

    问题: 今天老师讲了Servlet路径问题, 做了个测试在eclipse中启动tomcat后,在浏览器地址栏输入 http://localhost8080无法访问, 提示404错误, 正常情况是可以访 ...

  7. (转载) @ConfigurationProperties 注解使用姿势,这一篇就够了

    SpringBoot中的@ConfigurationProperties 传送门: http://www.hellojava.com/a/82613.html

  8. 【夯实基础】- https和http的主要区别

    HTTPS和HTTP的区别主要如下: 1.https协议需要到ca申请证书,一般免费证书较少,因而需要一定费用. 2.http是超文本传输协议,信息是明文传输,https则是具有安全性的ssl加密传输 ...

  9. vue中keep-alive,include的指定页面缓存问题

    做vue项目时,有时要在某些页面做缓存,而其它页面不要.比如:A:首页,B:获取所有订单页面,C:订单详情页面:从A(首页)进入 B(获取所有订单)时应该不缓存,B(所有订单)进入 C(订单详情)订单 ...

  10. 调用Hybris API时遇到的错误消息Cannot find user with uid如何解决

    今天工作中试图调用Commerce Cloud的user creation API用代码创建Hybris用户时,遇到下面这个错误消息. 我觉得很奇怪,因为backoffice里能查到这个id为jerr ...