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. debian下系列下的apt-get 命令与deb包的手动安装的dpkg命令

    手动下载的deb包的相关操作: 操作deb 使用dpkg 命令工具, dpkg 是Debian package的简写. 下面列举常用的 操作: dpkg –I name.deb  查看 包的详细信息( ...

  2. Altera特殊管脚的使用(适用全系列Altera FPGA,MSEL区别除外)-来自altera论坛

    1.I/O, ASDO  在AS 模式下是专用输出脚,在PS 和JTAG 模式下可以当I/O 脚来用.在AS 模式下,这个脚是CII 向串行配置芯片发送控制信号的脚.也是用来从配置芯片中读配置数据的脚 ...

  3. c#调用cmd

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  4. 基于mvcpager的分页(get请求,刷新页面),提供两种样式(来自bootstrap的样式)

    使用方法:先把mvcpager.dll引用加入mvc项目 下载路径在本文末尾 前台代码 前台: @{ Layout = null; } @using Webdiyer.WebControls.Mvc ...

  5. php获取QQ头像并显示的方法

    鉴于此,我在想一个大众化的,比较简单的方法,我想到的是对于没有头像的朋友调用其QQ头像, 因为QQ现在至少是人手一个,所以只需要留言时填写QQ号,然后调用其头像,这样一来就方便多了. 首先是获取QQ的 ...

  6. MathType编辑物理单位的方法

    在用MathType编辑物理公式时,由于物理单位很多都是复合单位,所以在编辑时如果能够有这种复合单位直接使用的话,编辑效率就会大大提高.实际上这种想法在MathType中是可行的,MathType中也 ...

  7. Shell 文本处理工具

    转载自:http://www.cnblogs.com/wish123/p/5540210.html Linux下使用Shell处理文本时最常用的工具: find.grep.xargs.sort.uni ...

  8. (转载)用vs2010开发基于VC++的MFC 串口通信一*****两台电脑同一个串口号之间的通信

    此文章以visual C++数据採集与串口通信測控应用实战为參考教程 此文章适合VC++串口通信入门 一.页面布局及加入控件 1, 安装好vs2010如图 2, 新建一个基于VC++的MFC项目com ...

  9. Android开发之程序猿必需要懂得Android的重要设计理念2(5.20更新版)

    上篇文章介绍了Android开发的设计理念的一部分,并没有得到博友们的多大认可,仅仅看到了一位博友在以下留言期待下一篇文章的发表,为了这小小的唯一支持.我决定继续把后面的8个要点介绍一下,自己也潜心反 ...

  10. api数据接口

    阿凡达数据 http://www.avatardata.cn/ 聚合数据 https://www.juhe.cn/