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个, 如果你现在手里 ...
随机推荐
- bzoj 2802 [Poi2012]Warehouse Store STL
[Poi2012]Warehouse Store Time Limit: 10 Sec Memory Limit: 64 MBSec Special JudgeSubmit: 621 Solve ...
- 通过一个用户管理实例学习路由react-router-dom知识
我们通过一个用户管理实例来学习react-router-dom 这个实例包括9个小组件 App.js 引入组件 Home.js 首页组件 User.js 用户管理组件 - UserList.js 用 ...
- 应对ADT(Eclipse)的No more handles解决办法
应对ADT(Eclipse)的No more handles解决方法 ADT(Eclipse)最近几天经常出现如下错误对话框:org.eclipse.swt.SWTError: No more han ...
- 【BZOJ4475】子集选取(计数)
题意: 思路: #include<cstdio> #include<cstdlib> #include<iostream> #include<algorith ...
- Spring Data Redis配置项有多少(不列举具体,只提供找的方法)
首先,要说明Spring Data Redis集成了很多款客户端,比如Jedis这些. 而如果在注入Bean时,我们一般是可以设置一些项的,比如hostName和port等,对于这些项一般的查找方式通 ...
- 一次mysql 优化 (Using temporary ; Using filesort)
遇到一个SQL执行很慢 SQL 如下: SELECT ... FROM tableA WHERE time >= 1492044535 and time <= 1492046335 GRO ...
- 删除,“windows setup 启用EMS”
方案1[笔者推荐]:进入Windows后按Windows+R输入msconfig回车进入系统配置,切换到引导,点击你要删除的选项然后点击删除就行[1].
- 30分钟学会如何使用Shiro(转)
本文转自http://www.cnblogs.com/learnhow/p/5694876.html 感谢作者 本篇内容大多总结自张开涛的<跟我学Shiro>原文地址:http://jin ...
- hash_map与unordered_map区别
http://blog.csdn.net/blues1021/article/details/45054159
- cocoapods应用第一部分-xcode创建.framework相关
问题的提出: 随着项目的越来越大,可能会出现好几个团队共同维护一个项目的情况,比如:项目组A负责当中的A块,项目组B负责当中的B块.....这几块彼此之间既独立,也相互联系.对于这样的情况,能够採用约 ...