比赛传送门

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. SQL基础--&gt;层次化查询(START BY ... CONNECT BY PRIOR)

    --====================================================== --SQL基础-->层次化查询(START BY ... CONNECT BY ...

  2. oracle 11G direct path read 非常美也非常伤人

    direct path read 在11g中,全表扫描可能使用direct path read方式,绕过buffer cache,这种全表扫描就是物理读了. 在10g中,都是通过gc buffer来读 ...

  3. 利用ms17_010漏洞实验

    1.理论 在MSF里面msfconsole可以说是最流行的一个接口程序.但是msfconsole真的是一个强大的接口程序.Msfconsole提供了一个一体化的集中控制台.通过msfconsole,你 ...

  4. SGU 194 Reactor Cooling 无源汇带上下界可行流

    Reactor Cooling time limit per test: 0.5 sec. memory limit per test: 65536 KB input: standard output ...

  5. gcc编译minigui新程序报错

    !ggcc *.c  -ljpeg -lpng  -lminigui -lpthread/usr/local/lib/libminigui.so: undefined reference to `dl ...

  6. JAVA学习第十九课(java程序的异常处理 (二))

    异常处理的捕捉形式: 这是能够对异常进行针对性处理的方式 六.try.catch的理解 详细格式: try { //须要被检測异常的代码 } catch(异常类 变量)//改变量用于接受发生异常的对象 ...

  7. 安装sbt

    http://www.scala-sbt.org/0.13/docs/zh-cn/Installing-sbt-on-Linux.html [root@hadoop1 target]# curl ht ...

  8. ZeroMQ 初步认识

    http://www.danieleteti.it/zeromq-for-delphi/ https://my.oschina.net/zeroflamy/blog/109457 http://zer ...

  9. 用WaveX实现音频文件的录音

    原文地址:https://blog.csdn.net/gongluck93/article/details/53096013 1.WaveInOpen waveInOpen MMRESULT wave ...

  10. YTU 2832: 使用指针访问数组元素--程序填空

    2832: 使用指针访问数组元素--程序填空 时间限制: 1 Sec  内存限制: 128 MB 提交: 328  解决: 160 题目描述 输入10个整数值到数组中,使用指针来完成对这10个数组元素 ...