比赛传送门

A. Make a triangle!

题目大意:给你三根木棒,选出其中一根木棒增加它的长度,使构成三角形,问增加的长度最小是多少。

思路:签到题,根据样例/三角形性质不难发现,答案就是最长边减剩下两边之和加一。

 #include<cstdio>
#include<algorithm> using namespace std; int seq[]; int main()
{
for(int i=;i<=;i++) scanf("%d",&seq[i]);
sort(seq+,seq++);
if(seq[]+seq[]>seq[]){printf("");return ;}
printf("%d",seq[]-(seq[]+seq[])+);
return ;
}

A

B. Equations of Mathematical Magic

题目大意:多组数据,每组给你一个$a$,求$a-(a xor x)-x=0$方程的解的个数。

思路:开始发现答案范围在0~a用二进制表示的几位最大的数(即a在二进制下有x位,则上限为$2^x$。)于是打了个200的表,发现与a的二进制表示下有多少个1有关。但是验证这个想法的时候,实现出锅了,于是耽搁了好久...后来发现自己的想法是正确的。设a的二进制表示下有x个1,那么最终答案就是$2^x$。

 #include<cstdio>
#include<algorithm> using namespace std; int T,a; int work(int x)
{
int tmp=x,cnt=;
while(tmp)
{
if(tmp%==) cnt++;
tmp/=;
}
return cnt;
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&a);
int hu=work(a);
int ans=(<<hu);
printf("%d\n",ans);
}
return ;
}

B

C. Oh Those Palindromes

题目大意:给你一个字符串,你可以对其中的字符进行任意调换顺序,求变换后的一个字符串,使得新字符串有最多的回文子串。(注意,可能有多个,输出一个即可)

思路:想这个题一个多小时都没搞出来...结束后发现核心代码只有5行??被样例蒙蔽了...感觉还需要不同的字母间匹配什么的,其实只需要把字符串中相同的字符排在一起就行了。

One possible solution is just to sort the string.

Why so?

Note that each palindrome have equal character at their ends. Suppose this character is cc with xx number of occurences. Then there are at most x(x+1)/2 palindromes with this character.

So we have a clear upper bound on answer. It is easy to see, that the sorted string fulfills that bound and hence(因此) it is the optimal(理想的) answer.(官方题解)

至于为什么是x(x+1)/2....

Since 'c' has x number of occurrences, thus palindrome with 'c' are x , palindrome which are 'cc' are x-1 , palindrome which are 'ccc' are x-2 and so on.

so we get x+x-1+....+2+1 = x(x+1)/2 for 'c' which has frequency x.

简单的加法原理==。

唉被这道题坑了,于是我现在就是真·pupil了...

 #include<cstdio>
#include<algorithm>
#include<iostream> using namespace std; int n;
string x; int main()
{
scanf("%d",&n);
cin>>x;
sort(x.begin(),x.end());
cout<<x;
return ;
}

C

D. Labyrinth

题目大意:在一个棋盘中,你从起点出发,问能到达多少点,但有向左走不超过$x$步,向右走不超过$y$步的限制。

思路1:如果没有那个限制,就是简单的$bfs$了。然后看了一位Chinese大神写的,每次我们要想使答案最优,一定要尽量走左右移动少的。

于是就可以用优先队列维护$l+r$少的状态,进行$bfs$。

 #include<cstdio>
#include<algorithm>
#include<queue> using namespace std; int n,m,r,c,llim,rlim,ans;
int dx[]={,-,,,};
int dy[]={,,,,-};
bool vis[][];
char tmp[],mapp[][];
struct node{
int x,y,l,r;
};
bool operator < (const node &x,const node &y)
{
return x.l+x.r>y.l+y.r;
} bool valid(int x,int y)
{
if(x>=&&x<=n&&y>=&&y<=m) return ;
return ;
} void bfs(int r,int c)
{
priority_queue<node>q;
node p;
p.x=r,p.y=c,p.l=,p.r=;
q.push(p);vis[r][c]=;
while(!q.empty())
{
node u=q.top();q.pop();
for(int i=;i<=;i++)
{
int nowx=u.x+dx[i];
int nowy=u.y+dy[i];
int nowl=u.l+(dy[i]==-);
int nowr=u.r+(dy[i]==);
if(!valid(nowx,nowy)||mapp[nowx][nowy]=='*') continue;
if(nowl>llim||nowr>rlim) continue;
if(!vis[nowx][nowy])
{
vis[nowx][nowy]=;
node tmp;
tmp.x=nowx,tmp.y=nowy;
tmp.l=nowl,tmp.r=nowr;
q.push(tmp);
}
}
}
} int main()
{
scanf("%d%d",&n,&m);
scanf("%d%d",&r,&c);
scanf("%d%d",&llim,&rlim);
for(int i=;i<=n;i++)
{
scanf("%s",tmp+);
for(int j=;j<=m;j++) mapp[i][j]=tmp[j];
}
bfs(r,c);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if(vis[i][j]) ans++;
printf("%d",ans);
return ;
}

D

还有一个很妙的想法:https://www.cnblogs.com/zwfymqz/p/9789569.html

这次是真惨..C题没做出来,成功成为了pupil....

话说我怎么这么菜啊

Codeforces Round #516 Div2 (A~D)By cellur925的更多相关文章

  1. Codeforces Round#498(Div.3)D. Two Strings Swaps

    题目 题意是给了两个字符串a和b,然后可以对这两个字符串有三种操作来使这两个字符串相等,一是交换a[i]和b[i],二是交换a[i]和a[n-i+1],三是交换b[i]和b[n-i+1],这三个操作都 ...

  2. CodeForces Round #516 Div2 题解

    A. Make a triangle! 暴力... 就是给你三个数,你每次可以选一个加1,问最少加多少次能构成三角形 #include <bits/stdc++.h> #define ll ...

  3. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  4. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  5. Codeforces 828B Black Square(简单题)

    Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...

  6. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  7. Codeforces C. Maximum Value(枚举二分)

    题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  9. Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) D. Labyrinth(重识搜索)

    https://codeforces.com/contest/1064/problem/D 题意 给你一个有障碍的图,限制你向左向右走的次数,问你可以到达格子的个数 思路 可以定义状态为vi[x][y ...

随机推荐

  1. php操作xml的方法

    xml源文件 <?xml version="1.0 encoding="UTF-8"?> <humans> <zhangying> & ...

  2. ISC DHCP: Enterprise grade solution for configuration needs

    https://www.isc.org/downloads/dhcp/ ISC DHCP: Enterprise grade solution for configuration needs All ...

  3. SQL 通配符及其使用

    Sql Server中通配符的使用 通配符_ "_"号表示任意单个字符,该符号只能匹配一个字符."_"可以放在查询条件的任意位置,且只能代表一个字符.一个汉字只 ...

  4. Arcgis Engine(ae)接口详解(4):featureClass的feature插入

    //由于测试数据不完善,featureClass在此要只设null值,真实功能要设实际的值 IFeatureClass featureClass = null; //获取某个字段的索引,后面取字段值用 ...

  5. 项目Beta冲刺(团队7/7)

    项目Beta冲刺(团队7/7) 团队名称: 云打印 作业要求: 项目Beta冲刺(团队) 作业目标: 完成项目Beta版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 陈宇 ...

  6. VC FTP服务器程序分析(一)

    想在QT上移植一个FTP服务器程序,先学习windows下的FTP服务器例子,然后随便动手写点东西. 在pudn上搜索 "FTP服务器端和客户端实现 VC“这几个关键字,就可以搜到下面要分析 ...

  7. python 将屏幕输出定向到变量中

    #!/usr/bin/python # -*- coding: utf-8 -*- import sys import subprocess as sp def main(): cmd = 'syst ...

  8. css3中我们不知道的一些属性

    1.图片作为边框:border-image; 2.圆角问题:border-radius:上.下.左.右: 3.字体的阴影与自动换行: 阴影: h1 {text-shadow: 5px 5px 5px ...

  9. Bootloader与Kernel间参数传递机制 taglist【转】

    本文转载自:http://blog.csdn.net/tommy_wxie/article/details/9187821 Tag list被用来在bootloader和Linux kernel 之间 ...

  10. HDU 5178 pairs —— 思维 + 二分

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5178 pairs Time Limit: 2000/1000 MS (Java/Others)     ...