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. [USACO12MAR]拖拉机

    题目描述 After a long day of work, Farmer John completely forgot that he left his tractor in the middle ...

  2. 【POJ3294】Life Forms(后缀数组,二分)

    题意: n<=100 len[i]<=1000 思路:这是一道论文题 ..]of longint; ch:..]of ansistring; n,n1,l,r,mid,last,i,j,m ...

  3. poj -1185 炮兵阵地 (经典状压dp)

    http://poj.org/problem?id=1185 参考博客:http://poj.org/problem?id=1185 大神博客已经讲的很清楚了,注意存状态的时候是从1开始的,所以初始化 ...

  4. Extjs.panel.Panel赋值的问题

    初学extjs,很是不爽.也是只有初学者才犯的错误,发出来以免再犯. 先创建一个panel var panel1 = Ext.create('Ext.panel.Panel', { id: 'p1', ...

  5. 使用Spring Data Redis操作Redis(单机版)

    说明:请注意Spring Data Redis的版本以及Spring的版本!最新版本的Spring Data Redis已经去除Jedis的依赖包,需要自行引入,这个是个坑点.并且会与一些低版本的Sp ...

  6. 报错: The type ByteInputStream is not accessible due to restriction on required library

    报错: Access restriction:The type JPEGCodec is not accessible due to restriction on required library C ...

  7. jenkins节约硬盘空间的几个办法

    jenkins真是费硬盘和内存,我们先聊聊硬盘问题怎么解决: 1.不要保留太多的构建记录.发布包数量 相关描述如下:取最先匹配进行执行 2.构建完,删除吧

  8. 【OpenGL】Shader实例分析(七)- 雪花飘落效果

    转发请保持地址:http://blog.csdn.net/stalendp/article/details/40624603 研究了一个雪花飘落效果.感觉挺不错的.分享给大家,效果例如以下: 代码例如 ...

  9. Windows 上通过本地搭建 Jekyll环境

    一 准备Ruby环境 1 我们首先须要安装Ruby.从站点下载Ruby 上下载Ruby最新版和对应的DevKit. 我下载的是Ruby 2.1.4 (x64)和DevKit-mingw64-6 .注意 ...

  10. springMVC4(16)拦截器解析与登陆拦截模拟

    在SpringMVC中,我们会常常使用到拦截器,尽管SpringAOP也能帮我们实现强大的拦截器功能,但在Web资源供给上.却没有SpringMVC来得方便快捷. 使用SpringMVC拦截器的核心应 ...