比赛传送门

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. 【翻译自mos文章】怎么找到OGG Director Server使用的数据库和username?

    APPLIES TO: Management Pack for Oracle GoldenGate - Version: 1.0.0.0 - Release: 1.0 Information in t ...

  2. Oracle创建索引的原则(转)

    Oracle 建立索引及SQL优化 数据库索引: 索引有单列索引复合索引之说 如何某表的某个字段有主键约束和唯一性约束,则Oracle 则会自动在相应的约束列上建议唯一索引.数据库索引主要进行提高访问 ...

  3. 芯片史称:“长平之战”----Intel的东进与ARM的西征(3)--人生如戏,全靠演技

    http://www.36kr.com/p/177143.html 从 2003 年到 2008 年,处理器双雄 Intel 和 AMD 在 64 位 CPU 领域展开了一场长达五年,极为惨烈的科技战 ...

  4. linux 输入子系统(1) -Event types

    输入系统协议用类型types和编码codecs来表示输入设备的值并用此来通知用户空间的应用程序. input协议是一个基于状态的协议,只有当相应事件编码对应的参数值发生变化时才会发送该事件.不过,状态 ...

  5. MySQL优化之——触发器

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46763665 触发器是一个特殊的存储过程,不同的是存储过程要用CALL来调用,而触 ...

  6. POJ 1182 食物链(并查集)

    题目链接 经过宝哥的讲解,终于对这种问题有了进一步的理解.根据flag[x]和flag[y]求flag[tx]是最关键的了. 0吃1,1吃2,2吃0. 假设flag[tx] = X; 那么X + fl ...

  7. ArrayList遍历的4种方法

    public class ArrayListDemo { public static void main(String args[]){ List<String> list = new A ...

  8. C# 事件处理与自定义事件

    http://blog.csdn.net/cyp403/article/details/1514023 图一                                               ...

  9. MyEclipse 8.5 启动过程优化

    前言:MyEclipse5.5 大小 139M:MyEclipse6.5 大小 451M:MyEclipse7.0 大小 649M:MyEclipse8.0 大小 772.3MB(速度方面比7.1和7 ...

  10. iOS 获取WIFI SSID及MAC地址

    NSString *ssid = @"Not Found"; NSString *macIp = @"Not Found"; CFArrayRef myArra ...