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的更多相关文章

  1. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  2. Codeforces Round #433 (Div. 2)【A、B、C、D题】

    题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...

  3. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  4. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  5. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  6. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  7. Codeforces Round #626 Div2 D,E

    比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...

  8. CodeForces Round 192 Div2

    This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...

  9. Codeforces Round #359 div2

    Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...

随机推荐

  1. firefox自动化测试的常用插件

    1.firebug 2.firepath 3.firefinder 5.WebDriver Element Locator 提供多种语言的xpath路径

  2. 最小生成树求法 Prim + Kruskal

    prim算法的思路 和dijkstra是一样的 每次选取一个最近的点 然后去向新的节点扩张 注意这里的扩张 不再是 以前求最短路时候的到新的节点的最短距离 而是因为要生成一棵树 所以是要连一根最短的连 ...

  3. 【2018 Multi-University Training Contest 3】

    01:https://www.cnblogs.com/myx12345/p/9420198.html 02: 03: 04:https://www.cnblogs.com/myx12345/p/940 ...

  4. React学习之State

    本文基于React v16.4.1 初学react,有理解不对的地方,欢迎批评指正^_^ 一.定义组件的两种方式 1.函数定义组件 function Welcome(props) { return & ...

  5. Space Ant--poj1696(极角排序)

    http://poj.org/problem?id=1696 极角排序是就是字面上的意思   按照极角排序 题目大意:平面上有n个点然后有一只蚂蚁他只能沿着点向左走  求最多能做多少点 分析:  其实 ...

  6. 洛谷——P1546 最短网络 Agri-Net

    P1546 最短网络 Agri-Net 题目背景 农民约翰被选为他们镇的镇长!他其中一个竞选承诺就是在镇上建立起互联网,并连接到所有的农场.当然,他需要你的帮助. 题目描述 约翰已经给他的农场安排了一 ...

  7. [Bzoj3233][Ahoi2013]找硬币[基础DP]

    3233: [Ahoi2013]找硬币 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 924  Solved: 482[Submit][Status][ ...

  8. vue学习001 --环境搭建

    系统 : win cmd: cmder 链接:https://cmder.net/ 1.安装node.js 链接地址: http://cdn.npm.taobao.org/dist/node/v10. ...

  9. Eclipse注释模板配置

    不过感觉作用不大,因为@date这些不是标准的Java注释.

  10. 框架-Jquerychange事件数值计算

    //优惠率计算优惠价            $("body").on("change", "#Rate", function() {     ...