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.求最少需要几 ...
随机推荐
- 阿里巴巴矢量库IconFont__使用小录
使用阿里巴巴矢量库方法虽然不难,但本人记性不好,遂在次记录几笔 阿里巴巴矢量库地址:http://www.iconfont.cn/plus 阿里巴巴矢量库图标好处: 1:图标矢量化 2:自己总结:ic ...
- (转)OpenLayers3基础教程——OL3之Popup
http://blog.csdn.net/gisshixisheng/article/details/46794813 概述: 本节重点讲述OpenLayers3中Popup的调用时实现,OL3改用O ...
- Linux 之常用操作指令详解
1. 查看当做操作目录位置 > pwd 2. 查看(当前)目录里边的文件内容 > ls //list > ls -l 或ll //显示文件的详细信息 > ls -al //al ...
- 用电销机器人让电销企业迈入AI智能时代
2019年是AI智能快速发展的一年,有非常多的企业已经用AI智能代替原有的传统员工做重复性高的工作,就拿销售行业来说,为了让电销员工提升工作效率,拥有更多的成单,大部分有电销岗位的公司都会把重复率较高 ...
- javascript匿名函数及闭包深入理解及应用
1.匿名函数 函数是JavaScript中最灵活的一种对象,这里只是讲解其匿名函数的用途.匿名函数:就是没有函数名的函数. 1.1 函数的定义,首先简单介绍一下函数的定义,大致可分为三种方式 第一种: ...
- Testbench文件编写纪要(Verilog)
之前在使用Verilog做FPGA项目中.以及其他一些不同的场合下,零散的写过一些练手性质的testbench文件,开始几次写的时候,每次都会因为一些基本的东西没记住.写的很不熟练,后面写的时候稍微熟 ...
- kvm介绍、安装及创建虚拟机
kvm虚拟化介绍 一.虚拟化分类 1.虚拟化,是指通过虚拟化技术将一台计算机虚拟为多台逻辑计算机.在一台计算机上同时运行多个逻辑计算机,每个逻辑计算机可运行不同的操作系统,并且应用程序都可以在相互独立 ...
- 谨慎调整内核参数:vm.min_free_kbytes
内核参数:内存相关 内存管理从三个层次管理内存,分别是node, zone ,page; 64位的x86物理机内存从高地址到低地址分为: Normal DMA32 DMA.随着地址降低. [root@ ...
- Linux基础:find命令总结
本文只总结一些常用的用法,更详细的说明见man find和 info find. find命令 find命令常用来查找文件或目录,可以根据给定的路径和表达式查找所需的文件或目录.该工具是由findut ...
- 转载:Java中的Checked Exception——美丽世界中潜藏的恶魔?
转自 Amber-Garden 的 博客 https://www.cnblogs.com/loveis715/p/4596551.html 在使用Java编写应用的时候,我们常常需要通过第三方类库来帮 ...