2015ACM/ICPC亚洲区上海站
题意:给你一个二叉树,根节点为1,子节点为父节点的2倍和2倍+1,从根节点开始依次向下走k层,问如何走使得将路径上的数进行加减最终结果得到n。
联想到二进制。
思路和这个差不多吧:http://blog.csdn.net/u013068502/article/details/50094561
#include <set>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
#define mem(x,y) memset(x, y, sizeof(x))
#define lson l,m,rt << 1
#define rson m+1,r,rt << 1 | 1
? a : gcd(b, a % b);}
int lcm(int a, int b){return a / gcd(a, b) * b;}
int main()
{
int T;
scanf("%d", &T);
; cas <= T; cas++)
{
;
scanf("%d%d", &n, &k);
== )
{
n--;
flag = ;
}
LL all = ( << (k + )) - ;
LL res = (all - n) >> ;
printf("Case #%d:\n", cas);
; i < k; i++)
{
LL temp = << i;
)) printf( : temp);
) printf("%I64d -\n", temp);
else printf("%I64d +\n", temp);
res >>= ;
}
}
;
}
题意:给你一个字符串,找最近的相同字符
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
#define mem(x,y) memset(x, y, sizeof(x))
#define lson l,m,rt << 1
#define rson m+1,r,rt << 1 | 1
? a : gcd(b, a % b);}
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 0x3f3f3f3f;
];
int main()
{
int T;
scanf("%d", &T);
getchar();
; cas <= T; cas++)
{
scanf("%s", s);
int len = strlen(s);
int ans = INF;
; i < len; i++)
{
; j < len; j++)
{
if(s[i] == s[j])
{
ans = min(ans, abs(i - j));
}
}
}
printf( : ans);
}
;
}
5583 Kingdom of Black and White
题意:给你一个01字符串,要求最多改变一个字符(即0->1或1->0),使相邻相同字符的平方和最大
漏了考虑,改变中间一个区间之后,两个到三个区间变成相同字符的情况。WA了。
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
#define mem(x,y) memset(x, y, sizeof(x))
#define lson l,m,rt << 1
#define rson m+1,r,rt << 1 | 1
? a : gcd(b, a % b);}
int lcm(int a, int b){return a / gcd(a, b) * b;}
;
int s[maxn];
LL len[maxn];
int main()
{
int T;
scanf("%d", &T);
getchar();
; cas <= T; cas++)
{
mem(s, -);
char ch;
;
while(~scanf("%c", &ch))
{
if(ch == '\n') break;
s[slen++] = ch - ';
}
, cur = , cnt = ;
while(cur <= slen)
{
])
{
len[cnt++] = cur - temp;
temp = cur;
}
cur++;
}
LL ans = ;
; i < cnt; i++)
{
ans += len[i] * len[i];
}
LL rec = ans;
; i < cnt; i++)
{
) break;
] == && i != )
{
ans = max(ans,
rec - len[i - ] * len[i - ] - len[i - ] * len[i - ] - len[i] * len[i]
+ (len[i - ] + len[i - ] + len[i]) * (len[i - ] + len[i - ] + len[i]));
}
])
{
ans = max(ans, rec + * (len[i - ] - len[i] + ));
}
])
{
ans = max(ans, rec + * (len[i] - len[i - ] + ));
}
}
printf("Case #%d: %I64d\n", cas, ans);
}
;
}
题意:有一只青蛙,它从起点(x,y)出发,每次它会走 LCM(x,y) 步到达点 (x+LCM(x,y),y) 或点 (x,y+LCM(x,y)) ,最终,它会到达点(ex,ey),现给你终点(ex,ey),要你求出它的起点有多少种可能。
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
#define mem(x,y) memset(x, y, sizeof(x))
#define lson l,m,rt << 1
#define rson m+1,r,rt << 1 | 1
? a : gcd(b, a % b);}
int lcm(int a, int b){return a / gcd(a, b) * b;}
;
int main()
{
int T, fx, fy;
scanf("%d", &T);
; cas <= T; cas++)
{
scanf("%d%d", &fx, &fy);
LL ans = ;
)
{
int g = gcd(fx, fy);
if(fy > fx) swap(fx, fy);
) break;
int m1 = fx / (fy + g);
int m2 = fy / g;
fx = m1 * g;
fy = m2 * g;
ans++;
}
printf();
}
;
}
2015ACM/ICPC亚洲区上海站的更多相关文章
- HDU-5583-Kingdom of Black and White(2015ACM/ICPC亚洲区上海站-重现赛)
Kingdom of Black and White ...
- (HDU 5558) 2015ACM/ICPC亚洲区合肥站---Alice's Classified Message(后缀数组)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5558 Problem Description Alice wants to send a classi ...
- 2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building
House Building Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- 2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree
Partial Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- 2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 2015ACM/ICPC亚洲区长春站 F hdu 5533 Almost Sorted Array
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild
Rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- 2015ACM/ICPC亚洲区长春站 B hdu 5528 Count a * b
Count a * b Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Tot ...
随机推荐
- webpack入坑之旅
转自: http://guowenfh.github.io/2016/03/24/vue-webpack-01-base/ http://guowenfh.github.io/2016/03/25/v ...
- yield和send的执行循序彻底搞清
yield: 对于yield方法和Generator的send同时使用时的执行顺序一直搞不清,今天看到这篇 理解PHP中的Generator 加上测试,终于搞清了. 总结一下上文中的结论: Gener ...
- eclipse android工程没有错却出现红叉
[转]eclipse android工程没有错却出现红叉 问题描述: 这是一个很变态的问题,花了我N多时间才解决掉,而且弄得心情非常郁闷,这明显是ADT的bug嘛,为什么最新的版本还没有解决? 将Li ...
- Hadoop概括——学习笔记<一>
之前有幸在MOOC学院抽中小象学院hadoop体验课. 这是小象学院hadoop2.X概述第一章的笔记 第一章主要讲的是hadoop基础知识.老师讲的还是比较全面简单的,起码作为一个非专业码农以及数据 ...
- 浅谈JSON
JSON的全称是”JavaScript Object Notation”,意思是JavaScript对象表示法,它是一种基于文本,独立于语言的轻量级数据交换格式.XML也是一种数据交换格式,为什么没有 ...
- 微信小程序开发视频教程新鲜出炉
微信小程序开发公测了,可是对于新手来说,不同的框架不同的开发机制,如何快速适应呢?微信小程序开发视频教程新鲜出炉了,从零开始一步一步搭建微信小程序,每个章节都会涉及到不同的知识点,等教程学习完你不但掌 ...
- 使用phpMyAdmin修改MySQL数据库root用户密码
点击顶部的“SQL”标签进入sql命令输入界面.输入以下命令: update mysql.user set password=PASSWORD('snsgou$123456') where user= ...
- Mac Pro 实现 PHP-5.6 与 PHP-7.0 等多版本切换
先前参考 如何 实现PHP多版本的 共存 和 切换? 实现了Linux(Ubuntu/CentOS)系统下,PHP多版本的切换,但是在 Mac OS 下,由于用户权限控制的比较严格,文章里提到的脚本运 ...
- 妈妈再也不用担心别人问我是否真正用过redis了
1. Memcache与Redis的区别 1.1. 存储方式不同 1.2. 数据支持类型 1.3. 使用底层模型不同 2. Redis支持的数据类型 3. Redis的回收策略 4. Redis小命令 ...
- Spring中的JdbcTemplate使用
1.引出SpringJDBC的概念 在学习JDBC编程时我们会感觉到JDBC的操作是多么繁琐,那么当我们学习的Hibernate框架时,我们感觉到数据库的操作也变非常简单,提高了开发效率.但是当使用H ...