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. vi/vim复制粘贴命令

    1. 选定文本块.使用v进入可视模式,移动光标键选定内容. 2.复制的命令是y,即yank(提起) ,常用的命令如下:     y      在使用v模式选定了某一块的时候,复制选定块到缓冲区用:   ...

  2. C. Nearest vectors--cf598C(极角排序)

    http://codeforces.com/problemset/problem/598/C 题目大意: 给你你个向量  向量的起点都是从(0,0)开始的   求哪个角最小  输出这两个向量 这是第一 ...

  3. poj 3041——Asteroids

    poj       3041——Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22604   Accep ...

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

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

  5. Spring AOP Capability and Goal

    AOP Capability: 1.Spring声明式事务管理配置. 2.Controller层的参数校验. 3.使用Spring AOP实现MySQL数据库读写分离案例分析 4.在执行方法前,判断是 ...

  6. Atom编辑Markdown文件保存后行尾的空格自动消失的问题解决

    Markdown文件的行尾增加两个空格表示一行结束需要换行. 但保存文件后,行尾的空格自动消失,导致不换行. 解决方法: 1.[Edit]->[Preferences]->[Package ...

  7. openstack swift middleware开发

    首先MiddleWare核心代码,这段代码卸载swift的源代码目录下,~/swift/swift/common/middleware下新建deletionpreventing.py: import ...

  8. eclipse提速03 - 禁用动画

  9. grep使用正则表达式搜索IP地址

    递归搜索当前目录及其子目录.子目录的子目录……所包含文件是否包含IP地址 grep -r "[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit: ...

  10. 配置activeMQ

    一.加入以下的库 并配置好路径 ws2_32.lib;Mswsock.lib;cppunit.lib;libapr-1.lib;libapriconv-1.lib;libaprutil-1.lib;l ...