A---Make a triangle!

http://codeforces.com/contest/1064/problem/A

题意:

给定三个整数表示三角形的边。每次给边长可以加一,问至少要加多少才能使这三个边成为一个三角形。

思路:

找到最大的边,然后最大边 + 1减剩下两条边就行了。负数的话就是0。

 #include<iostream>
#include<cmath>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<bits/stdc++.h> #define inf 0x3f3f3f3f
using namespace std;
typedef long long LL; int a, b, c; int main(){ while(scanf("%d%d%d", &a, &b, &c) != EOF){
int m = max(a, b);
m = max(m, c);
int ans = ;
if(m == a){
if(b + c > m){
ans = ;
}
else{
ans = m + - b - c;
}
}
else if(m == b){
if(a + c > m){
ans = ;
}
else{
ans = m + - a - c;
}
}
else{
if(a + b > m){
ans = ;
}
else{
ans = m + - a - b;
}
}
printf("%d\n", ans);
}
return ;
}

B---Equations of Mathematical Magic

http://codeforces.com/contest/1064/problem/B

题意:

给定一个a, 使得a - (a ^ x) - x = 0.问能有多少的x。

思路:

如果a的某一位是1, x的这一位是1,那么a^x这一位是0,a-(a^x)-x这一位是0

如果a的某一位是1, x的这一位是0, 那么a^x这一位是1,a-(a^x)-x这一位是0

如果a的某一位是0, x的这一位是1, 那么a^x这一位是1,a-(a^x)-x这一位是1

如果a的某一位是0, x的这一位是0,那么a^x这一位是0,a-(a^x)-x这一位是0

所以统计一下a的1的个数

 #include<iostream>
#include<cmath>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<bits/stdc++.h> #define inf 0x3f3f3f3f
using namespace std;
typedef long long LL; int t;
LL a; int main(){ while(scanf("%d", &t) != EOF){
for(int i = ; i < t; i++){
scanf("%I64d", &a);
LL cnt = ;
while(a){
if(a & ){
cnt <<= ;
}
a >>= ;
} printf("%I64d\n", cnt);
} } return ;
}

C---Oh Those Palindromes

http://codeforces.com/contest/1064/problem/C

题意:

给定一个字符串,使得他的是回文的子串数目最多,问应如何重新排列这个字符串。

思路:

让同一个字母都放在一起,输出就行了。sort一下就行,但是我竟然还统计了一下个数,蠢了。

 #include<iostream>
#include<cmath>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<bits/stdc++.h> #define inf 0x3f3f3f3f
using namespace std;
typedef long long LL; int n;
const int maxn = 1e5 + ;
char str[maxn];
int cnt[]; int main(){ while(scanf("%d", &n) != EOF){
//scanf("%s", str);
cin>>str;
memset(cnt, , sizeof(cnt));
for(int i = ; i < n; i++){
cnt[str[i] - 'a']++;
}
for(int i = ; i < ; i++){
for(int j = ; j < cnt[i]; j++){
printf("%c", i+'a');
}
}
printf("\n");
}
return ;
}

D---Labyrinth

http://codeforces.com/contest/1064/problem/D

题意:

一个n*m的格子,有的格子有障碍不能经过。现在从(r, c)处出发,向左最多只能走x次,向右最多走y次,问可以到达的格子有多少个。

思路:

最开始想的是dfs直接更新啥的。但是由于有先后顺序的问题,所以更新的时候左右的次数是不能直接减1的。需要用数组记录一下最大的左右次数。

而且如果发现vis过了这个格子就不更新了的话,也还是有先后顺序的问题。只有当经过这个格子的左右次数比原来大的时候才继续dfs更新这个格子。

但是这样dfs会T。

czc bfs过了,明天试一下....

先贴一下T了的代码。

 #include<iostream>
#include<cmath>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<bits/stdc++.h> #define inf 0x3f3f3f3f
using namespace std;
typedef long long LL; int n, m, r, c, x, y, cnt;
const int maxn = ;
bool vis[maxn][maxn];
int leftl[maxn][maxn], leftr[maxn][maxn];
int mvi[] = {, , , -};
int mvj[] = {, -, , };
bool g[maxn][maxn]; void dfs(int posi, int posj)
{
if(!vis[posi][posj]){
vis[posi][posj] = true;
//cout<<posi<<" "<< posj<<endl;
cnt++;
}
for(int k = ; k < ; k++){
int di = posi + mvi[k];
int dj = posj + mvj[k];
int mostl,mostr;
if(di > && dj > && di <= n && dj <= m && g[di][dj]){
if(k == ){//向右
mostr = leftr[posi][posj] - ;
mostl = leftl[posi][posj];
if(mostr > leftr[di][dj] && mostr >= ){
leftr[di][dj] = mostr;
leftl[di][dj] = mostl;
dfs(di, dj);
}
}
else if(k == ){
mostl = leftl[posi][posj] - ;
mostr = leftr[posi][posj];
if(mostl > leftl[di][dj] && mostl >= ){
leftl[di][dj] = mostl;
leftr[di][dj] = mostr;
dfs(di, dj);
}
}
else{
mostl = leftl[posi][posj];
mostr = leftr[posi][posj];
if(mostl > leftl[di][dj]){
leftl[di][dj] = mostl;
leftr[di][dj] = mostr;
dfs(di, dj);
}
}
}
}
} int main(){ while(scanf("%d%d", &n, &m) != EOF){
scanf("%d%d", &r, &c);
scanf("%d%d", &x, &y);
cnt = ;
memset(vis, , sizeof(vis));
memset(leftr, -, sizeof(leftr));
memset(leftl, -, sizeof(leftl)); for(int i = ; i <= n; i++){
char str[maxn];
scanf("%s", str);
for(int j = ; j < m; j++){
if(str[j] == '*'){
g[i][j + ] = false;
}
else{
g[i][j + ] = true;
}
}
} leftl[r][c] = x;
leftr[r][c] = y;
dfs(r, c);
printf("%d\n", cnt);
}
return ;
}

bfs写的 1A代码

 #include<iostream>
#include<cmath>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<bits/stdc++.h> #define inf 0x3f3f3f3f
using namespace std;
typedef long long LL; int n, m, r, c, x, y, cnt;
const int maxn = ;
bool vis[maxn][maxn];
int leftl[maxn][maxn], leftr[maxn][maxn];
int mvi[] = {, , , -};
int mvj[] = {, -, , };
bool g[maxn][maxn]; void dfs(int posi, int posj)
{
if(!vis[posi][posj]){
vis[posi][posj] = true;
//cout<<posi<<" "<< posj<<endl;
cnt++;
}
for(int k = ; k < ; k++){
int di = posi + mvi[k];
int dj = posj + mvj[k];
int mostl,mostr;
if(di > && dj > && di <= n && dj <= m && g[di][dj]){
if(k == ){//ÏòÓÒ
mostr = leftr[posi][posj] - ;
mostl = leftl[posi][posj];
if(mostr > leftr[di][dj] && mostr >= ){
leftr[di][dj] = mostr;
leftl[di][dj] = mostl;
dfs(di, dj);
}
}
else if(k == ){
mostl = leftl[posi][posj] - ;
mostr = leftr[posi][posj];
if(mostl > leftl[di][dj] && mostl >= ){
leftl[di][dj] = mostl;
leftr[di][dj] = mostr;
dfs(di, dj);
}
}
else{
mostl = leftl[posi][posj];
mostr = leftr[posi][posj];
if(mostl > leftl[di][dj]){
leftl[di][dj] = mostl;
leftr[di][dj] = mostr;
dfs(di, dj);
}
}
}
}
} struct node{
int i, j;
node(){}
node(int _i, int _j):i(_i), j(_j){}
}; void bfs()
{
queue<node>que;
que.push(node(r, c));
vis[r][c] = true;
cnt = ;
while(!que.empty()){
node now = que.front();
que.pop();
for(int k = ; k < ; k++){
int di = now.i + mvi[k], dj = now.j + mvj[k];
if(di > && di <= n && dj > && dj <= m && g[di][dj]){
/*if(!vis[di][dj]){
vis[di][dj] = true;
cnt++;
}*/
if(k == ){
int mostl = leftl[now.i][now.j], mostr = leftr[now.i][now.j] - ;
if(mostr >= && !vis[di][dj]){
vis[di][dj] = true;
cnt++;
}
if(mostr >= && mostr > leftr[di][dj]){
que.push(node(di, dj));
leftl[di][dj] = mostl;
leftr[di][dj] = mostr;
}
}
else if(k == ){
int mostl = leftl[now.i][now.j] - , mostr = leftr[now.i][now.j];
if(mostl >= && !vis[di][dj]){
vis[di][dj] = true;
cnt++;
}
if(mostl >= && mostl > leftl[di][dj]){
que.push(node(di, dj));
leftl[di][dj] = mostl;
leftr[di][dj] = mostr;
}
}
else{
int mostl = leftl[now.i][now.j], mostr = leftr[now.i][now.j];
if(!vis[di][dj]){
vis[di][dj] = true;
cnt++;
}
if(mostl > leftl[di][dj]){
que.push(node(di, dj));
leftl[di][dj] = mostl;
leftr[di][dj] = mostr;
}
}
}
}
}
printf("%d\n", cnt);
} int main(){ while(scanf("%d%d", &n, &m) != EOF){
scanf("%d%d", &r, &c);
scanf("%d%d", &x, &y);
cnt = ;
memset(vis, , sizeof(vis));
memset(leftr, -, sizeof(leftr));
memset(leftl, -, sizeof(leftl)); for(int i = ; i <= n; i++){
char str[maxn];
scanf("%s", str + );
for(int j = ; j <= m; j++){
if(str[j] == '*'){
g[i][j] = false;
}
else{
g[i][j] = true;
}
}
} leftl[r][c] = x;
leftr[r][c] = y;
bfs();
//cout<<"!"<<endl;
//dfs(r, c);
//printf("%d\n", cnt);
}
return ;
}

上了31分,ABC都卡了一下,C还RE了一发,还是太菜了啊。

codeforces#516 Div2---ABCD的更多相关文章

  1. Codeforces #107 DIV2 ABCD

    A #include <map> #include <set> #include <list> #include <cmath> #include &l ...

  2. [codeforces 516]A. Drazil and Factorial

    [codeforces 516]A. Drazil and Factorial 试题描述 Drazil is playing a math game with Varda. Let's define  ...

  3. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  4. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  5. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  6. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  7. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  8. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  9. CodeForces Round #516 Div2 题解

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

  10. Codeforces Round #412 div2 ABCD

    A 按rank给出每个人的赛前分数和赛后分数 如果一个人打败了比他分数高的人 他的分数必然升高 问比赛rated吗 如果一个人的分数改变了肯定rate 如果全都没改的话 也可能是rated 这时候ch ...

随机推荐

  1. 学习:erlang的不定长数据包头部。

  2. 【Java面试题】24 sleep() 和 wait() 有什么区别? 详细解析!!!!

    第一种解释: 功能差不多,都用来进行线程控制,他们最大本质的区别是:sleep()不释放同步锁,wait()释放同步缩.         还有用法的上的不同是:sleep(milliseconds)可 ...

  3. CentOS6.8设置开机直接进入命令行模式

    在linux图形界面中,按 “Alt+Ctrl+F1”,进入命令行界面. 切换到root用户 # vi /etc/inittab 找到下面的语句: # Default runlevel. The ru ...

  4. electron-searchMovies

    之前学了electron,前段时间又学了一下vue,为了增加熟练度决定将两者结合做个有趣的东西.想来想去最后决定将原来用 PyQt 写的MovieHeavens重新写一遍,使用electron-vue ...

  5. shell脚本程序中循环、判断语句的介绍

    shell的循环主要有3种,for,while,until shell的分支判断主要有2种,if,case 一,for循环 C/C++ Code复制内容到剪贴板 #!/bin/bash for fil ...

  6. ScSR超分辨率的效果

  7. nagios监控mysql

    在nagios上部署check_mysql_health 监控mysql 博客分类: 架构   本监控为基于nagios服务器主动监控方法,利用check_mysql_health实现多种监控模式:  ...

  8. YARN应用程序开发和设计流程

    从业务的角度看,一个应用需要分两部分进行开发,一个是接入YARN平台,实现3个协议,通过YARN实现对集群资源的访问和利用:另一个是业务功能的实现,这个与YARN本身没有太大关系.下面主要阐述如何将一 ...

  9. surfaceView和View的区别

    概念:view在UI线程去更新自己:而SurfaceView则在一个子线程中去更新自己 surfaceView是在一个新起的单独线程中可以重新绘制画面,而View必须在UI的主线程中更新画面 在UI的 ...

  10. 基于Cocos2d-x学习OpenGL ES 2.0系列——OpenGL ES渲染之LayerColor(8)

    在前面文章中讲述了Cocos2d-x引擎OpenGL渲染准备Shader方面,本文主要讲解使用LayerColor来讲述OpenGL的渲染过程. 1.LayerColor对象创建 添加LayerCol ...