Educational Codeforces Round49
A Palindromic Twist(字符串)
问每个字母必须向左或向右变成另一个字母,问能不能构成回文
#include <iostream>
#include <string.h>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>
#include <string>
#include <algorithm>
#include <time.h> #define SIGMA_SIZE 26
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) (x&-x)
#define foe(i, a, b) for(int i=a; i<=b; i++)
#define fo(i, a, b) for(int i=a; i<b; i++);
//#pragma warning ( disable : 4996 ) using namespace std;
typedef long long LL;
inline LL LMax(LL a, LL b) { return a>b ? a : b; }
inline LL LMin(LL a, LL b) { return a>b ? b : a; }
inline LL lgcd(LL a, LL b) { return b == ? a : lgcd(b, a%b); }
inline LL llcm(LL a, LL b) { return a / lgcd(a, b)*b; } //a*b = gcd*lcm
inline int Max(int a, int b) { return a>b ? a : b; }
inline int Min(int a, int b) { return a>b ? b : a; }
inline int gcd(int a, int b) { return b == ? a : gcd(b, a%b); }
inline int lcm(int a, int b) { return a / gcd(a, b)*b; } //a*b = gcd*lcm
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = ;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const int maxk = 1e6 + ;
const int maxn = 5e5+; int len;
char str[]; int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif int T; cin >> T;
while(T--)
{
scanf("%d", &len);
scanf("%s", str+);
if (len == )
{
printf("YES");
continue;
} int mid;
int l, r, tmp;
bool ok = true;
mid = len/;
for ( int i = ; i <= mid; i++ )
{
l = i; r = len-i+;
tmp = abs(str[l]-str[r]);
if (tmp > || tmp == )
{
//cout << tmp << endl;
ok = false;
break;
}
}
if (ok)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
B Numbers on the Chessboard(模拟)
题意简单,写起来容易错,主要是将矩阵每两层作为一大层(+N),然后判断所在点是前面有几层
#include <iostream>
#include <string.h>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>
#include <string>
#include <algorithm>
#include <time.h> #define SIGMA_SIZE 26
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) (x&-x)
#define foe(i, a, b) for(int i=a; i<=b; i++)
#define fo(i, a, b) for(int i=a; i<b; i++);
//#pragma warning ( disable : 4996 ) using namespace std;
typedef long long LL;
inline LL LMax(LL a, LL b) { return a>b ? a : b; }
inline LL LMin(LL a, LL b) { return a>b ? b : a; }
inline LL lgcd(LL a, LL b) { return b == ? a : lgcd(b, a%b); }
inline LL llcm(LL a, LL b) { return a / lgcd(a, b)*b; } //a*b = gcd*lcm
inline int Max(int a, int b) { return a>b ? a : b; }
inline int Min(int a, int b) { return a>b ? b : a; }
inline int gcd(int a, int b) { return b == ? a : gcd(b, a%b); }
inline int lcm(int a, int b) { return a / gcd(a, b)*b; } //a*b = gcd*lcm
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = ;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const int maxk = 1e6 + ;
const int maxn = 5e5+; LL n, q; int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif cin >> n >> q;
int x, y;
while(q--)
{
LL ans = ;
LL tmp;
scanf("%d %d", &x, &y);
if ((x+y)%==) {
int h = x%;
tmp = h ? x/ : (x-)/;
if (h) {
ans = n*tmp + (y/)+;
}
else {
ans = n*tmp + (n/)+(y/);
if (n%) ans++;
}
}
else {
int h = x%;
tmp = h ? x/ : (x-)/;
if (h) {
ans = n*tmp + (y/);
}
else {
ans = n*tmp + (n/) + (y+)/;
}
if (n%)
ans += (n*n)/+;
else
ans += (n*n)/;
}
printf("%lld\n", ans);
}
return ;
}
C Minimum Value Rectangle
很容易推出最后结果和(a/b)+(b/a)有关,根据均值不等式肯定两个值越近越小,所以把可行边排序后每次选择枚举距离最相近的两种边选最小
#include <iostream>
#include <string.h>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>
#include <string>
#include <algorithm>
#include <time.h> #define SIGMA_SIZE 26
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) (x&-x)
#define foe(i, a, b) for(int i=a; i<=b; i++)
#define fo(i, a, b) for(int i=a; i<b; i++)
//#pragma warning ( disable : 4996 ) using namespace std;
typedef long long LL;
inline LL LMax(LL a, LL b) { return a>b ? a : b; }
inline LL LMin(LL a, LL b) { return a>b ? b : a; }
inline LL lgcd(LL a, LL b) { return b == ? a : lgcd(b, a%b); }
inline LL llcm(LL a, LL b) { return a / lgcd(a, b)*b; } //a*b = gcd*lcm
inline int Max(int a, int b) { return a>b ? a : b; }
inline int Min(int a, int b) { return a>b ? b : a; }
inline int gcd(int a, int b) { return b == ? a : gcd(b, a%b); }
inline int lcm(int a, int b) { return a / gcd(a, b)*b; } //a*b = gcd*lcm
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = ;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const int maxk = 1e6+;
const int maxn = 1e6+; int n, cnt;
int a[maxn];
int num[maxn]; void init()
{
cin >> n;
cnt = ; int tmp;
foe(i, , n)
scanf("%d", &a[i]);
sort(a+, a++n); tmp = ;
foe(i, , n)
{
if (a[i] == a[i-]) {
if (!tmp) {
num[++cnt] = a[i];
tmp++;
}
else {
tmp = ;
}
}
else {
tmp = ;
}
}
} int main()
{
#ifndef ONLINE_JUDGE
freopen("input_2.txt", "r", stdin);
#endif int T; cin >> T;
while(T--)
{
init(); double tmp, ans = inf;
int a, b;
//cout << cnt << endl;
fo(i, , cnt)
{
tmp = (double)*num[i]/num[i+] + (double)*num[i+]/num[i];
if ( tmp < ans )
{
ans = tmp;
a = i; b = i+;
}
}
printf("%d %d %d %d\n", num[a], num[a], num[b], num[b]);
}
return ;
}
D Mouse Hunt
有只耗子在n个房子内乱串,当此时刻耗子在i房间时,下一时刻耗子会移动到a[i]号房间,在i房间布置捕鼠器需要耗费c[i],开始耗子位置随机,问最少消耗多少能保证一定捕捉到老鼠
根据题意我们需要判断连通量和环,因为耗子顺着一条路走下去最后必然在某一个点后走到原先的某点形成一个环,所以用并查集判环,在该环上寻找最小cost就行了
#include <iostream>
#include <string.h>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>
#include <string>
#include <algorithm>
#include <time.h> #define SIGMA_SIZE 26
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) (x&-x)
#define foe(i, a, b) for(int i=a; i<=b; i++)
#define fo(i, a, b) for(int i=a; i<b; i++)
//#pragma warning ( disable : 4996 ) using namespace std;
typedef long long LL;
inline LL LMax(LL a, LL b) { return a>b ? a : b; }
inline LL LMin(LL a, LL b) { return a>b ? b : a; }
inline LL lgcd(LL a, LL b) { return b == ? a : lgcd(b, a%b); }
inline LL llcm(LL a, LL b) { return a / lgcd(a, b)*b; } //a*b = gcd*lcm
inline int Max(int a, int b) { return a>b ? a : b; }
inline int Min(int a, int b) { return a>b ? b : a; }
inline int gcd(int a, int b) { return b == ? a : gcd(b, a%b); }
inline int lcm(int a, int b) { return a / gcd(a, b)*b; } //a*b = gcd*lcm
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = ;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const int maxk = 1e6+;
const int maxn = 2e5+; int n;
int cost[maxn], to[maxn];
int fa[maxn];
bool vis[maxn];
vector<int> ans; int _find(int x)
{
if (x == fa[x])
return fa[x];
return fa[x] = _find(fa[x]);
} //将y作为父节点
void merge(int x, int y)
{
int xr = _find(x);
int yr = _find(y);
if (xr != yr)
fa[xr] = y;
} int dfs(int x, int y)
{
if (x == y) return cost[x];
return Min(dfs(x, to[y]), cost[y]);
} void init()
{
cin >> n; foe(i, , n) scanf("%d", &cost[i]);
foe(i, , n)
{
scanf("%d", &to[i]);
fa[i] = i;
vis[i] = false;
}
} int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif init();
//并查集判环
foe(i, , n) {
if (_find(to[i]) == _find(i)) {
vis[i] = true;
continue;
} merge(i, to[i]);
} int ans = ;
//foe(i, 1, n)
// printf("%d\n", vis[i]);
foe(i, , n)
if (vis[i])
ans += dfs(i, to[i]);
printf("%d\n", ans);
return ;
}
Educational Codeforces Round49的更多相关文章
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
- Educational Codeforces Round 9
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
随机推荐
- Jboss集群(五)--F5硬件负载均衡器双击热备 + Jboss集群终极实现
BIG/IP利用定义在其上面的虚拟IP地址来为用户的一个或多个应用服务器提供服务.因此,它能够为大量的基于TCP/IP的网络应用提供服务器负载均衡服务.BIG/IP连续地对目标服务器进行L4到L7合理 ...
- spring boot部署到阿里云碰到的总总问题
2375错误,我没装docker,从pom中删了吧 mysql,不能写本机对外,得写127.0.0.1. 如何生成jar包,在pom中写上jar <groupId>com.coding&l ...
- nginx中reuqest_uri与uri的区别说明
reuqest_uri:即客户端发送来的原生请求URI,包括请求参数 uri:请求URI,不包括任何请求参数 举例说明: 1.比如客户端以 get 方式请求 /admin 页面,并且带 id 和 na ...
- Excel的数据分析—排位与百分比
Excel的数据分析-排位与百分比 某班级期中考试进行后,按照要求仅公布成绩,但学生及家长要求知道排名.故欲公布成绩排名,学生可以通过成绩查询到自己的排名,并同时得到该成绩位于班级百分比排名(即该同学 ...
- MDK KEIL 机构体初始化 . 点 成员 初始化, C99
C99介绍,参考这里:C89,C99: C数组&结构体&联合体快速初始化 MDK 设置: 只需添加 ”--c99"参数即可,如图:
- shell 命令 修改文件权限 chmod
1. 所有者+.-权限 更改那个拥有者的权限 u 表示文件的所有者 g 表示文件所在的组 o 表示其他用户 a 所有,以上三者 增加 / 减少权限 + 表示增加权限 - 表示取消权限 更改具体 ...
- C++ 系列:交换两个数字
1. 创建中间变量 这是最快也是最简单的办法,例如: #include<stdio.h> int main(){ int a=10; int b=20; int temp; printf( ...
- Erlang学习记录:运算符
数学运算符 说明 详细 符号 加减乘 +-* 浮点数除 结果为浮点数 / 整数除 除数和被除数都必须是整数,结果为整数 div 整数取余 rem 逻辑运算符 说明 符号 详细 and 前后两个值都为真 ...
- 解析Spring第二天
目的:使用spring中纯注解的方式 前言:同样是使用idea创建一个普通的maven工程(如何创建一个普通的Maven工程可以参考mybatis入门第一天的详解). bean管理类常用的4个注解(作 ...
- Windows 10 连接服务器
{ windows + r input mstsc } { //mstsc D:\TOOL\Servers.rdp /v 127.0.0.1:9998 }