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. python 脚本检测python 版本

    通过sys 模块的sys_info可以返回当前python 的版本信息, 其返回值是一个元组, 比如(2, 6, 6, 'final', 0); 表示当前版本为2.6.6 , 我们可以利用这个变量的值 ...

  2. 查看Centos系统最近一次启动时间和运行时间

    1.uptime命令 [spark@Master Log_Data]$ uptime 09:18:01 up 20:17,  1 user,  load average: 0.13, 0.12, 0. ...

  3. CentOS定位、查找文件的命令

    定位.查找文件的命令 命令 功能 命令 功能 which 从path中找出文件的位置 find 找出所有符合要求的文件 whereis 找出特定程序的路径 locate 从索引中找出文件位置 9.1 ...

  4. 【Java NIO的深入研究1】缓冲区

    缓冲区 传统的流和通道的对比 流 通道 慢 快 处理简单 处理复杂 单字节的传输 一块数据的传输 - Java.io.*已经重新写过 - 是对流的模拟 单向的 双向的 可直接访问 必须通过Buffer ...

  5. ASP.NET自带对象JSON字符串与实体类的转换

    关于JSON的更多介绍,请各位自行google了解!如果要我写的话,我也是去Google后copy!嘿嘿,一直以来很想学习json,大量的找资料和写demo,总算有点了解! 切入正题! 还是先封装一个 ...

  6. c# JsonHelper类

    using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...

  7. GIS-009-Cesium 使用

    //加载ArcGIS 发布的地图服务MapServervar url='http://Jason:6080/arcgis/rest/services/SampleWorldCities/MapServ ...

  8. ASP代码审计学习笔记-1.SQL注入

    ASP注入漏洞 一.SQL注入的原因 按照参数形式:数字型/字符型/搜索型 1.数字型sql查询 sql注入原因: ID=49 这类注入的参数是数字型,SQL语句原貌大致如下: id=request. ...

  9. Runtime应用(二)使用对象关联为分类增加属性(每个对象的属性互不干扰)

    一.对象的关联方法有 1. void objc_setAssociatedObject(id object, const void *key, id value,objc_AssociationPol ...

  10. SEH分析笔记(X64篇)

    SEH分析笔记(X64篇) v1.0.0 boxcounter 历史: v1.0.0, 2011-11-4:最初版本. [不介意转载,但请注明出处 www.boxcounter.com  附件里有本文 ...