codeforces round #433 div2
A:枚举一下就行了...居然wa了一发,题目一定要看清
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
cin >> n;
int mid = n / - ((n & ) == );
for(int i = n / ; i; --i)
{
if(__gcd(i, n - i) == )
{
printf("%d %d\n", i, n - i);
return ;
}
}
return ;
}
B:这道题有点恶心,就是判断当前能不能每三个点有一个居民,判断一下就可以了
#include<bits/stdc++.h>
using namespace std;
int n, k;
int main()
{
cin >> n >> k;
if(k == )
{
puts("0 0");
return ;
}
if(n == k || k == ) printf("0 ");
else printf("1 ");
int tmp1 = (n + ) / , tmp2 = (n + ) / , t = n % ;
if(k < tmp2) printf("%d\n", k * );
else printf("%d\n", n - k);
return ;
}
C:这种题只能贪心吧,似乎cf这种配对题都是贪心,开个set查询前继后继
#include<bits/stdc++.h>
using namespace std;
const int N = ;
struct data {
long long c;
int id;
bool friend operator < (data a, data b)
{
return a.c > b.c;
}
} a[N];
int n, k;
int answer[N];
set<long long> s;
int main()
{
cin >> n >> k;
for(int i = ; i <= n; ++i) scanf("%lld", &a[i].c), a[i].id = i, s.insert(i + k);
sort(a + , a + n + );
long long ans = ;
for(int i = ; i <= n; ++i)
{
long long t1 = *(s.lower_bound(a[i].id)), t2 = *(s.upper_bound(a[i].id)), tmp;
if(abs(a[i].id - t1) < abs(a[i].id - t2)) tmp = t1;
else tmp = t2;
s.erase(tmp);
ans += abs(a[i].id - tmp) * a[i].c;
answer[a[i].id] = tmp;
}
cout << ans << endl;
for(int i = ; i <= n; ++i) printf("%d ", answer[i]);
return ;
}
D:考试时想了会弃了...觉得大概是枚举一下...事实上枚举一下维护前缀后缀和就行了
#include<bits/stdc++.h>
using namespace std;
const int N = ;
const long long inf = ;
struct data {
int pos, cost;
data(int pos, int cost) : pos(pos), cost(cost) {}
};
vector<data> v1[N], v2[N];
int n, m, k, day, cnt;
int vis[N], can1[N], can2[N];
long long sum;
long long sum1[N], sum2[N], mn[N];
int main()
{
cin >> n >> m >> k;
for(int i = ; i <= m; ++i)
{
int d, f, t, c;
scanf("%d%d%d%d", &d, &f, &t, &c);
day = max(day, d);
if(t == ) v1[d].push_back(data(f, c));
else v2[d].push_back(data(t, c));
}
for(int i = ; i <= n; ++i) mn[i] = inf, sum += inf;
for(int i = ; i <= day; ++i)
{
for(int j = ; j < v1[i].size(); ++j)
{
data tmp = v1[i][j];
if(tmp.cost < mn[tmp.pos])
{
sum -= mn[tmp.pos];
sum += tmp.cost;
mn[tmp.pos] = tmp.cost;
}
if(vis[tmp.pos] == )
{
vis[tmp.pos] = ;
++cnt;
}
}
sum1[i] = sum;
if(cnt == n) can1[i] = ;
// printf("cnt = %d sum1[%d] = %lld can1[%d] = %d\n", cnt, i, sum1[i], i, can1[i]);
}
memset(vis, , sizeof(vis));
sum = ;
cnt = ;
for(int i = ; i <= n; ++i) mn[i] = inf, sum += inf;
for(int i = day; i ; --i)
{
for(int j = ; j < v2[i].size(); ++j)
{
data tmp = v2[i][j];
if(tmp.cost < mn[tmp.pos])
{
sum -= mn[tmp.pos];
sum += tmp.cost;
mn[tmp.pos] = tmp.cost;
}
if(vis[tmp.pos] == )
{
vis[tmp.pos] = ;
++cnt;
}
}
sum2[i] = sum;
if(cnt == n) can2[i] = ;
// printf("cnt = %d sum2[%d] = %lld can2[%d] = %d\n", cnt, i, sum2[i], i, can2[i]);
}
long long ans = 1ll << ;
// puts("------------------------");
for(int i = ; i <= day - k + ; ++i)
{
// printf("can1[%d] = %d can2[%d] = %d\n", i, can1[i], i + k + 1, can2[i + k + 1]);
if(can1[i] && can2[i + k + ]) ans = min(ans, sum1[i] + sum2[i + k + ]);
}
cout << ((ans == 1ll << ) ? - : ans) << endl;
return ;
}
E:考试时候石乐志觉得主席树爆空间...写了个莫队...然后错了...发现题目看错莫队做不了GG...其实很简单,静态查询区间点数,主席树维护一下,然后容斥做一下加减法就行了
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int size[N * ], lc[N * ], rc[N * ], root[N];
int n, q, cnt;
void update(int l, int r, int &x, int last, int pos)
{
size[x = ++ cnt] = size[last] + ;
lc[x] = lc[last];
rc[x] = rc[last];
if(l == r) return;
int mid = (l + r) >> ;
if(pos <= mid) update(l, mid, lc[x], lc[last], pos);
else update(mid + , r, rc[x], rc[last], pos);
}
int query(int l, int r, int x, int y, int a, int b)
{
if(l > b || r < a) return ;
if(l >= a && r <= b) return size[x] - size[y];
int mid = (l + r) >> ;
return (query(l, mid, lc[x], lc[y], a, b) + query(mid + , r, rc[x], rc[y], a, b));
}
int main()
{
cin >> n >> q;
for(int i = ; i <= n; ++i)
{
int x;
scanf("%d", &x);
update(, n, root[i], root[i - ], x);
}
while(q --)
{
int l, d, r, u;
scanf("%d%d%d%d", &l, &d, &r, &u);
long long ans = (long long)n * (long long)(n - ) / 2ll, tmp;
tmp = query(, n, root[n], root[], , d - );
ans -= tmp * (tmp - ) / 2ll;
tmp = query(, n, root[n], root[], u + , n);
ans -= tmp * (tmp - ) / 2ll;
tmp = query(, n, root[l - ], root[], , n);
ans -= tmp * (tmp - ) / 2ll;
tmp = query(, n, root[n], root[r], , n);
ans -= tmp * (tmp - ) / 2ll;
tmp = query(, n, root[n], root[r], u + , n);
ans += tmp * (tmp - ) / 2ll;
tmp = query(, n, root[l - ], root[], u + , n);
ans += tmp * (tmp - ) / 2ll;
tmp = query(, n, root[n], root[r], , d - );
ans += tmp * (tmp - ) / 2ll;
tmp = query(, n, root[l - ], root[], , d - );
ans += tmp * (tmp - ) / 2ll;
printf("%lld\n", ans);
}
return ;
}
codeforces round #433 div2的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- Codeforces Round #433 (Div. 2)【A、B、C、D题】
题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- Codeforces Round #359 div2
Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...
随机推荐
- 【板+背包】多重背包 HDU Coins
http://acm.hdu.edu.cn/showproblem.php?pid=2844 [题意] 给定n种价值为Ci,个数为Wi的硬币,问在1~V中的这些数中哪些数能由这些硬币组成? [思路] ...
- 两行代码搞定UI主流框架
XCNavTab XCNavTab适用于快速搭建NavigationController和TabBarController相结合的框架 https://github.com/xiaocaiabc/XC ...
- 反编译sencha toucha打包的apk文件,修改应用名称支持中文以及去除应用标题栏
一.去除安卓应用标题栏 sencha touch打包android安装包,去掉标题栏titlebar的简单方法 (有更复杂更好的方法,参看"二.利用反编译修改apk的应用名称为中文" ...
- 【ZJOI2017 Round1练习】
喜闻乐见(爆蛋滚粗)的ZJOI模拟赛终于开始了 可以又一次感受被屠的快感 DAY1: T1:线段树打错-70 正解分块听卡常还要调块的大小 T2:数学弱爆 是道结论题 T3:暴力分滚粗 DAY2: T ...
- CentOS6 Install kafka
https://www.cnblogs.com/caoguo/p/5958608.html
- 牛客网暑期ACM多校训练营(第九场)D
链接:https://www.nowcoder.com/acm/contest/147/D来源:牛客网 Niuniu likes traveling. Now he will travel on a ...
- 洛谷——P1347 排序
洛谷—— P1347 排序 题目描述 一个不同的值的升序排序数列指的是一个从左到右元素依次增大的序列,例如,一个有序的数列A,B,C,D 表示A<B,B<C,C<D.在这道题中,我们 ...
- P1003 铺地毯(noip 2011)
洛谷——P1003 铺地毯 题目描述 为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯.一共有 n 张地毯,编号从 1 到n .现在将这些地毯 ...
- Python 基础语法(和Java相比)
Python变量和数据类型 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ...
- android-调用系统的ContentPrivder获取单张图片实现剪切做头像及源代码下载
首先讲述这个小项目的特色: 1.调用系统的相冊应用获取单张图片 2.对单张图片进行剪切方便做成指定大小的头像图片 3.对获取图片的结果进行解析,使用三种方式进行. 首先看看效果图: 打开app,进入注 ...