AtCoder Regular Contest 069
1. C - Scc Puzzle
计算scc的个数,先判断s个数需要多少个cc,多的cc,每四个可以组成一个scc。注意数据范围,使用long long.
#include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + ;
void solve() {
ll x, y;
while(cin >> x >> y) {
ll res = ;
if(y >= * x) {
res = x + (y - * x) / ;
} else {
res = y / ;
}
cout << res << endl;
}
}
int main() {
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
ios::sync_with_stdio();
cin.tie(); cout.tie();
solve();
return ;
}
2. D - Menagerie
读完题目,感觉是无从下手,3 <= n <= 1e5,暴力判断每一个字符串,肯定会tle,然后就要想其他方法了。
然后突然想到:固定前2个数,然后其他的位置可以推导出来,最后判断第一个和最后一个位置是否合法就可以了。
我写的又长又臭,哎,先这样吧,慢慢改进。
#include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + ;
int n;
vector<bool> res;
bool work(const string &s) {
for (int i = ; i < n - ; i++) {
if(s[i] == 'o') {
if(res[i]) {
res[i + ] = !res[i - ];
} else {
res[i + ] = res[i - ];
}
} else {
if(res[i]) {
res[i + ] = res[i - ];
} else {
res[i + ] = !res[i - ];
}
}
}
bool f1, f2;
f1 = f2 = ;
if(s[n - ] == 'o') {
if(res[n - ]) {
f1 = res[n - ] != res[];
} else {
f1 = res[n - ] == res[];
}
} else {
if(res[n - ]) {
f1 = res[n - ] == res[];
} else {
f1 = res[n - ] != res[];
}
} if(s[] == 'o') {
if(res[]) {
f2 = res[n - ] != res[];
} else {
f2 = res[n - ] == res[];
}
} else {
if(res[]) {
f2 = res[n - ] == res[];
} else {
f2 = res[n - ] != res[];
}
}
return f1 && f2;
}
void pr() {
for (int i = ; i < n; i++) {
if(res[i]) cout << 'W';
else cout << 'S';
}
cout << endl;
}
void solve() {
string s;
while(cin >> n) {
cin >> s;
res.clear();
res.resize(n);
res[] = res[] = ;
bool f = work(s);
if(f) {
pr();
continue;
}
res[] = res[] = ;
f = work(s);
if(f) {
pr();
continue;
}
res[] = ; res[] = ;
f = work(s);
if(f) {
pr();
continue;
}
res[] = ; res[] = ;
f = work(s);
if(f) {
pr();
continue;
}
cout << - << endl;
}
}
int main() {
// freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
ios::sync_with_stdio();
cin.tie(); cout.tie();
solve();
return ;
}
3. E - Frequency
1<=n<=1e5,1<=a<=1e9,数据范围很大,不可能一个一个的模拟。注意结果可能需要long long来保存。
考虑最大的数,然后递减到次大的数,然后每次维护一下这些数的index的最小值,依次统计,最后输出。
使用set来维护数的顺序,同时记录index.
#include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + ;
int a[maxn];
set<int> se;
map<int, vector<int>> tag;
map<int, int> sz;
ll res[maxn];
int n;
void solve() {
cin >> n;
for (int i = ; i < n; i++) {
cin >> a[i];
se.insert(a[i]);
sz[a[i] ]++;
tag[a[i] ].pb(i + );
}
while(se.size() > ) {
int t = *se.rbegin();
se.erase(t);
int nt = *se.rbegin();
int mi = tag[t][];
for (int x : tag[t]) {
mi = min(mi, x);
}
tag[nt].pb(mi);
res[mi] += 1ll * (t - nt) * sz[t];
sz[nt] += sz[t];
}
int t = *se.begin();
int mi = tag[t][];
for (int x : tag[t]) mi = min(mi, x);
res[mi] += 1ll * t * sz[t];
for (int i = ; i <= n; i++)
cout << res[i] << endl;
}
int main() {
// freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
ios::sync_with_stdio();
cin.tie(); cout.tie();
solve();
return ;
}
4。 F - Flags
题目很简短,不知道怎么做。官方题解只有日语的,没有进一步用翻译去看,有时间,搞一下。
AtCoder Regular Contest 069的更多相关文章
- AtCoder Regular Contest 069 F Flags 二分,2-sat,线段树优化建图
AtCoder Regular Contest 069 F Flags 二分,2-sat,线段树优化建图 链接 AtCoder 大意 在数轴上放上n个点,点i可能的位置有\(x_i\)或者\(y_i\ ...
- AtCoder Regular Contest 069 D
D - Menagerie Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement Snuke, w ...
- AtCoder Regular Contest 069 D - Menagerie 枚举起点 模拟递推
arc069.contest.atcoder.jp/tasks/arc069_b 题意:一堆不明身份的动物排成一圈,身份可能是羊或狼,羊一定说实话,狼一定说假话.大家各自报自己的两边是同类还是不同类, ...
- AtCoder Regular Contest 069 F - Flags
题意: 有n个点需要摆在一个数轴上,每个点需要摆在ai这个位置或者bi上,问怎么摆能使数轴上相邻两个点之间的距离的最小值最大. 二分答案后显然是个2-sat判定问题,因为边很多而连边的又是一个区间,所 ...
- AtCoder Regular Contest 061
AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...
- AtCoder Regular Contest 094 (ARC094) CDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...
- AtCoder Regular Contest 092
AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...
- AtCoder Regular Contest 093
AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...
- AtCoder Regular Contest 094
AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...
随机推荐
- Interrupt中断线程
package com.wistron.swpc.ecs.util; public class WrongWayStopThread extends Thread{ public static voi ...
- SLAM:飞行机器人的参数解析-分类
在水电站存在的山区,公路运输效率极低,盘山公路绕行消耗大量时间,使用飞行机器人进行运输是合适的选择. 实现一位长辈在山区飞行的愿望,任重而道远 常见飞行机器人的参数解析:解读飞行机器人的基本类型及技术 ...
- **ML : ML中的最优化方法
前言: 在机器学习方法中,若模型理解为决策模型,有些模型可以使用解析方法.不过更一般的对模型的求解使用优化的方法,更多的数据可以得到更多的精度. AI中基于归纳的方法延 ...
- mysql手册操作
1.show table status 显示表状态 2.VERSION() 版本:CURRENT_DATE 当前日期: NOW() 当前时间:USER 当前用户 3.GRANT A ...
- bpm被攻击事件
bpm登录不上,服务器是windows2008,从深信服上面设置了ddos每秒钟连接超5000次封锁,阻断后面的IP连接,,深信服DDOS日志没有记录 在bpm服务器上面通过netstat -a查看发 ...
- Linux—Ubuntu14.0.5安装mongo
1.安装mongo sudo apt-get install mongo 2.如果遇到找不到安装包运行,那就更新资源列表 sudo apt-get update 3.安装成功会自动运行mongo pg ...
- tree:以树形结构显示目录下的内容
tree命令 1.命令详解 [功能说明] tree命令的中文意思为“树”,功能是以树形结构列出指定目录下的所有内容包括所有文件.子目录及子目录里的目录和文件. [语法格式] tree [option] ...
- 26.bulk批量操作
主要知识点 1.bulk语法 2.bulk使用时的注意事项 3.bulk size 对es性能的影响 一.bulk语法 每一个操作要两个json串(delete操作除外),每个json串占一行 ...
- canvas实现圆框图片
作者:issac_宝华链接:http://www.jianshu.com/p/9a6ee2648d6f來源:简书 在html中做圆框图片很容易,只需要简单的 border-radius: 50%; 当 ...
- 5、Linux的常用命令
ls 查看当面目录结构 ls -l 列表查看当前目录 cd:切换目录 pwd:显示目前的目录 mkdir:创建一个新的目录 rmdir:删除一个空的目录 cp: 复制文件或目录 rm: 移除文件或目录 ...