CodeForces Round #516 Div2 题解
A. Make a triangle!
暴力...
就是给你三个数,你每次可以选一个加1,问最少加多少次能构成三角形
#include <bits/stdc++.h> #define ll long long
#define inf 0x3f3f3f3f
#define il inline
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d) inline void read( int &x ){
x = ; int f = ; char c = getchar() ;
while( c < '' || c > '' ) {
if( c == '-' ) f = - ;
c = getchar() ;
}
while( c >= '' && c <= '' ) {
x = (x << ) + (x << ) + c - ;
c = getchar() ;
}
x *= f ;
} inline void readl( ll &x ){
x = ; ll f = ; char c = getchar() ;
while( c < '' || c > '' ) {
if( c == '-' ) f = - ;
c = getchar() ;
}
while( c >= '' && c <= '' ) {
x = (x << ) + (x << ) + c - ;
c = getchar() ;
}
x *= f ;
} using namespace std ; #define N 100010 int a , b , c ; int main(){
in3( a ,b , c ) ;
if( a > b ) swap( a , b ) ;
if( b > c ) swap( b , c ) ;
if( a > c ) swap( a , c ) ;
int ans = ;
while( a + b <= c ) {
a ++ ;
ans ++ ;
if( a > b ) swap( a , b ) ;
}
printf( "%d\n" , ans ) ;
return ;
}
B. Equations of Mathematical Magic
求满足式子$a-(a\ xor\ x)-x=0$的$x$值的数量
$a<=2^{30}-1$
对于某一位的$a$和$x$
设$a$这一位上的数字为$a_i$,$x$这一位上的数字为$x_i$
对于$a_i=0$,只有$x_i=0$才成立
对于$a_i=1$,$x_i=0$或者$x_i=1$均成立
所以乘法原理乘一下就好了
ZincSabian聚聚抬了一手(orz我B题就不会了
#include <cstdio>
#include <cstring>
#include <algorithm> #define ll long long
#define inf 0x3f3f3f3f
#define il inline
#define in1(a) readl(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d) inline void read( int &x ){
x = ; int f = ; char c = getchar() ;
while( c < '' || c > '' ) {
if( c == '-' ) f = - ;
c = getchar() ;
}
while( c >= '' && c <= '' ) {
x = (x << ) + (x << ) + c - ;
c = getchar() ;
}
x *= f ;
} inline void readl( ll &x ){
x = ; ll f = ; char c = getchar() ;
while( c < '' || c > '' ) {
if( c == '-' ) f = - ;
c = getchar() ;
}
while( c >= '' && c <= '' ) {
x = (x << ) + (x << ) + c - ;
c = getchar() ;
}
x *= f ;
} using namespace std ; #define N 100010 ll T , a ; int main() {
in1( T ) ;
while( T -- ) {
in1( a ) ;
ll cnt = ;
for( int i = ; i >= ; i -- ) {
if( a&(1ll<<i) ) cnt *= 2ll ;
}
printf( "%lld\n" , cnt ) ;
}
}
C. Oh Those Palindromes
怎么B,C都是结论题啊
C题直接把所有一样的数排在一起就好了...
因为这样确实就能排出最大的回文串了
可以找几个字符串自己写写画画一下,感性理解
#include <cstdio>
#include <cstring>
#include <algorithm> #define ll long long
#define inf 0x3f3f3f3f
#define il inline
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d) inline void read( int &x ){
x = ; int f = ; char c = getchar() ;
while( c < '' || c > '' ) {
if( c == '-' ) f = - ;
c = getchar() ;
}
while( c >= '' && c <= '' ) {
x = (x << ) + (x << ) + c - ;
c = getchar() ;
}
x *= f ;
} inline void readl( ll &x ){
x = ; ll f = ; char c = getchar() ;
while( c < '' || c > '' ) {
if( c == '-' ) f = - ;
c = getchar() ;
}
while( c >= '' && c <= '' ) {
x = (x << ) + (x << ) + c - ;
c = getchar() ;
}
x *= f ;
} using namespace std ; #define N 100010 int n ;
char ch[ N ] ; int main(){
in1( n ) ;
scanf( "%s" , ch+ ) ;
sort( ch+ , ch+n+ ) ;
printf( "%s" , ch+ ) ;
}
D. Labyrinth
赛时没调出来...
然后赛后3min调出来
$system\ test$ 完后交了就过了
哭...掉分了
唔...其实这题就是建两个图,对于第一个图只有向左走才会花费代价,对于第二个图只有向右走才会花费代价
然后就是码码码了,我写了$4KB$...
写的$spfa$,网格图居然没卡$spfa$...
代码可能有点丑...
将就着看吧
#include <cstdio>
#include <cstring>
#include <algorithm> #define ll long long
#define debug printf("233\n")
#define inf 0x3f3f3f3f
#define il inline
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d) inline void read( int &x ){
x = ; int f = ; char c = getchar() ;
while( c < '' || c > '' ) {
if( c == '-' ) f = - ;
c = getchar() ;
}
while( c >= '' && c <= '' ) {
x = (x << ) + (x << ) + c - ;
c = getchar() ;
}
x *= f ;
} inline void readl( ll &x ){
x = ; ll f = ; char c = getchar() ;
while( c < '' || c > '' ) {
if( c == '-' ) f = - ;
c = getchar() ;
}
while( c >= '' && c <= '' ) {
x = (x << ) + (x << ) + c - ;
c = getchar() ;
}
x *= f ;
} using namespace std ; #define N 2010 int n , m , r , c , x , y ;
char ch[ N ][ N ] ;
struct edge {
int to , nxt , v ;
} e[ N * N * ] , E[ N * N * ];
int head[ N * N ] , cnt , Head[ N * N ] , Cnt ;
int vis[ N * N ] , d[ N * N ] , Vis[ N * N ] , D[ N * N ] ;
int q[ ] ; void ins1( int u , int v , int w ) {
e[ ++ cnt ].to = v ;
e[ cnt ].nxt = head[ u ] ;
e[ cnt ].v = w ;
head[ u ] = cnt ;
} void ins2( int u , int v , int w ) {
E[ ++ Cnt ].to = v ;
E[ Cnt ].nxt = Head[ u ] ;
E[ Cnt ].v = w ;
Head[ u ] = Cnt ;
} void spfa() {
int s = (r-) * m + c ;
q[ ] = s ;
int l = , r = ;
for( int i = ; i <= n * m ; i ++ ) d[ i ] = inf ;
d[ s ] = ;
vis[ s ] = ;
while( l != r ) {
int u = q[ l ++ ] ;
vis[ u ] = ;
if( l == ) l = ;
for( int i = head[ u ] ; i ; i = e[ i ].nxt ) {
int v = e[ i ].to ;
if( d[ v ] > d[ u ] + e[ i ].v ) {
d[ v ] = d[ u ] + e[ i ].v ;
if( !vis[ v ] ) {
vis[ v ] = ;
q[ r ++ ] = v ;
if( r == ) r = ;
}
}
}
}
} void spfa2() {
int s = (r-) * m + c ;
int l = , r = ;
q[ ] = s ;Vis[ s ] = ;
for( int i = ; i <= n * m ; i ++ ) D[ i ] = inf ;
D[ s ] = ;
while( l != r ) {
int u = q[ l ++ ] ;
Vis[ u ] = ;
if( l == ) l = ;
for( int i = Head[ u ] ; i ; i = E[ i ].nxt ) {
int v = E[ i ].to ;
if( D[ v ] > D[ u ] + E[ i ].v ) {
D[ v ] = D[ u ] + E[ i ].v ;
if( !Vis[ v ] ) {
Vis[ v ] = ;
q[ r ++ ] = v ;
if( r == ) r = ;
}
}
}
}
} int main(){
in2( n , m ) ;
in2( r , c ) ;
in2( x , y ) ;
for( int i = ; i <= n ; i ++ ) {
scanf( "%s" , ch[ i ] + ) ;
}
for( int i = ; i <= n ; i ++ ) {
for( int j = ; j <= m ; j ++ ) {
if( ch[ i ][ j ] == '*' ) continue ;
if(i->=&&ch[i-][j]=='.') ins1((i-)*m+j,(i-)*m+j,), ins2((i-)*m+j,(i-)*m+j,);
if(j->=&&ch[i][j-]=='.') ins1((i-)*m+j,(i-)*m+j-,),ins2((i-)*m+j,(i-)*m+j-,);
if(i+<=n&&ch[i+][j]=='.') ins1((i-)*m+j,i*m+j,), ins2((i-)*m+j,i*m+j,);
if(j+<=m&&ch[i][j+]=='.') ins1((i-)*m+j,(i-)*m+j+,),ins2((i-)*m+j,(i-)*m+j+,);
}
}
spfa() ;
spfa2() ;
int ans = ;
for( int i = ; i <= n * m ; i ++ ) {
if( d[ i ] <= x && D[ i ] <= y ) ans ++ ;
}
printf( "%d\n" , ans ) ;
}
E. Dwarves, Hats and Extrasensory Abilities
这题有点思路,晚上补一下
因为题目保证了白的在一边黑的在一边
所以我们可以二分这个分界点
然后输出的时候,纵坐标随便找两个,尽量让他们连线与坐标轴成45度角那样子
反正不要太歪,我取的纵坐标是$0$和$2$
就是真的很不习惯交互的形式
#include <bits/stdc++.h> #define ll long long
#define inf 0x3f3f3f3f
#define il inline
#define in1(a) readl(a) inline void readl( ll &x ){
x = ; ll f = ; char c = getchar() ;
while( c < '' || c > '' ) {
if( c == '-' ) f = - ;
c = getchar() ;
}
while( c >= '' && c <= '' ) {
x = (x << ) + (x << ) + c - ;
c = getchar() ;
}
x *= f ;
} using namespace std ; #define N 100010 ll n ;
ll x , y ;
char s[ N ] ; int main() {
in1( n ) ;
puts( "0 0" ) ;
fflush( stdout ) ;
scanf( "%s" , s ) ;
char tmp = s[ ] ;
ll l = , r = 1e9 ;
for( int i = ; i <= n ; i ++ ) {
ll mid = ( l + r ) >> ;
printf( "%lld %lld\n" , mid , 1ll ) ;
fflush( stdout ) ;
scanf( "%s" , s ) ;
if( s[ ] == tmp ) l = mid + ;
else r = mid - ;
}
printf( "%lld 0 %lld 2\n" , l , r ) ;
}
F. Candies for Children
以后补...
CodeForces Round #516 Div2 题解的更多相关文章
- [Codeforces Round #461 (Div2)] 题解
[比赛链接] http://codeforces.com/contest/922 [题解] Problem A. Cloning Toys [算法] 当y = 0 , 不可以 当 ...
- CodeForces round 967 div2 题解(A~E)
本来准备比完赛就写题解的, 但是一拖拖了一星期, 唉 最后一题没搞懂怎么做,恳请大神指教 欢迎大家在评论区提问. A Mind the Gap 稳定版题面 https://cn.vjudge.net/ ...
- Codeforces Round #407 div2 题解【ABCDE】
Anastasia and pebbles 题意:你有两种框,每个框可以最多装k重量的物品,但是你每个框不能装不一样的物品.现在地面上有n个物品,问你最少多少次,可以把这n个物品全部装回去. 题解:其 ...
- Codeforces Round #467(Div2)题解
凌晨起来打CF,0:05,也是我第一次codeforces 第一题: 我刚开始怀疑自己读错题了,怎么会辣么水. 判除了0的数字种类 #include <cstdio> ; ]; int m ...
- Codeforces Round #516 Div2 (A~D)By cellur925
比赛传送门 A. Make a triangle! 题目大意:给你三根木棒,选出其中一根木棒增加它的长度,使构成三角形,问增加的长度最小是多少. 思路:签到题,根据样例/三角形性质不难发现,答案就是最 ...
- Codeforces Round#704 Div2 题解(A,B,C,D,E)
FST ROUND !!1 A Three swimmers: 直接整除一下向上取整就好了: #include <bits/stdc++.h> using namespace std; t ...
- Codeforces Round#687 Div2 题解
打这场的时候迷迷糊糊的,然后掉分了( A Prison Break: 题面很复杂,但是题意很简单,仅需求出从这个点到四个角的最大的曼哈顿距离即可 #include <bits/stdc++.h& ...
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- Codeforces Round #543 Div1题解(并不全)
Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...
随机推荐
- 关于JS call apply 对象、对象实例、prototype、Constructor、__proto__
关于call与apply的理解容易让人凌乱,这里有个方法可供参考 tiger.call(fox,arg1,arg2...) tiger.apply(fox,[arg1,arg2...]) 理解为 fo ...
- tornado : 异步、非阻塞
The terms asynchronous and non-blocking are closely related and are often used interchangeably, but ...
- Kubernetes 1.8火热出炉:稳定性、安全性与存储支持能力全面提升
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/M2l0ZgSsVc7r69eFdTj/article/details/78130225 周三,Kub ...
- beginAppearanceTransition
- (void)beginAppearanceTransition:(BOOL)isAppearing animated:(BOOL)animated __OSX_AVAILABLE_STARTING ...
- HTML状态消息
HTTP 状态消息 当浏览器从 web 服务器请求服务时,可能会发生错误. 以下列举了有可能会返回的一系列 HTTP 状态消息: 1xx: 信息 消息: 描述: 100 Continue 服务器仅接收 ...
- 3.对神经网络训练中Epoch的理解
代表的是迭代的次数,如果过少会欠拟合,反之过多会过拟合 EPOCHS 当一个完整的数据集通过了神经网络一次并且返回了一次,这个过程称为一个 epoch. 然而,当一个 epoch 对于计算机而言太 ...
- 输出log到指定文件
0:pom.xml中添加依赖 <!--log4j--> <!--有错误时,可能版本不对,或者依赖没有加全 'org.apache.logging.log4j:log4j-core:2 ...
- django的serializers
views.py # get所需的 from snippets.serializers import SnippetSerializer from rest_framework.views impor ...
- .net 调用API并解析Json数据方法
using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using Syst ...
- Qt元对象系统简介
在Qt中提供了c++的扩展,提供了一种元对象系统的机制,(meta-object-system)的机制.其中包含了信号与槽的内部机制,能够访问到QObject子类的元对象信息的功能. Q_OBJECT ...