题目链接:http://codeforces.com/contest/818

A. Diplomas and Certificates

题解:水题

#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
int main() {
ll n , k;
cin >> n >> k;
ll gg = n / 2;
if(gg < (k + 1)) cout << 0 << ' ' << 0 << ' ' << n << endl;
else {
cout << gg / (k + 1) << ' ' << gg / (k + 1) * k << ' ' << n - gg / (k + 1) - gg / (k + 1) * k << endl;
}
return 0;
}

B. Permutation Game(构造)

题解:也是一道水题模拟构造一下就行了

if l[i + 1] > l[i]   a[l[i]] = l[i + 1] - l[i];
else    a[l[i]] = l[i + 1] - l[i] + n

最后没有被赋值的点敷一下值就行。

#include <iostream>
using namespace std;
int l[200] , a[200] , vis[200];
int main() {
int n , m;
cin >> n >> m;
int flag = 0;
for(int i = 1 ; i <= m ; i++) cin >> l[i];
for(int i = 1 ; i <= n ; i++) a[i] = 0;
for(int i = 1 ; i < m ; i++) {
if(l[i + 1] > l[i]) {
if(a[l[i]]) {
if(a[l[i]] != l[i + 1] - l[i]) {
flag = 1;
break;
}
}
a[l[i]] = l[i + 1] - l[i];
}
else {
if(a[l[i]]) {
if(a[l[i]] != l[i + 1] - l[i] + n) {
flag = 1;
break;
}
}
a[l[i]] = l[i + 1] - l[i] + n;
}
}
for(int i = 1 ; i <= n ; i++) {
vis[a[i]]++;
if(!a[i]) continue;
if(vis[a[i]] > 1) {
flag = 1;
break;
}
}
int cnt = 1;
for(int i = 1 ; i <= n ; i++) {
if(a[i] == 0) {
while(vis[cnt] != 0) cnt++;
a[i] = cnt;
vis[a[i]] = 1;
}
}
for(int i = 1 ; i <= n ; i++) if(!a[i]) {flag = 1; break;}
if(flag) cout << -1 << endl;
else {
for(int i = 1 ; i <= n ; i++) cout << a[i] << ' ';
cout << endl;
}
return 0;
}

C. Sofa Thief

题解:稍微有点麻烦的题目,主要还是求一下前缀,由于一个沙发占两格所以处理起来可能有点麻烦具体看一下代码最终还是要求前缀来解决这个问题。

#include <iostream>
#include <cstring>
using namespace std;
const int M = 1e5 + 10;
struct TnT {
int x1 , y1 , x2 , y2 , id;
}T[M];
int l[M] , r[M] , t[M] , b[M];
int sum[M];
int main() {
int d;
cin >> d;
int n , m;
cin >> n >> m;
for(int i = 1 ; i <= d ; i++) {
cin >> T[i].x1 >> T[i].y1 >> T[i].x2 >> T[i].y2 , T[i].id = i;
}
int cntl , cntr , cntt , cntb;
cin >> cntl >> cntr >> cntt >> cntb;
memset(sum , 0 , sizeof(sum));
for(int i = 1 ; i <= d ; i++) {
sum[min(T[i].x1 , T[i].x2)]++;
}
for(int i = 1 ; i <= n ; i++) {
sum[i] += sum[i - 1];
}
for(int i = 1 ; i <= d ; i++) {
if(T[i].x1 != T[i].x2) l[i] = sum[min(T[i].x1 , T[i].x2)] - 1;
else l[i] = sum[T[i].x1 - 1];
}
memset(sum , 0 , sizeof(sum));
for(int i = 1 ; i <= d ; i++) {
sum[max(T[i].x1 , T[i].x2)]++;
}
for(int i = n ; i >= 1 ; i--) {
sum[i] += sum[i + 1];
}
for(int i = 1 ; i <= d ; i++) {
if(T[i].x1 != T[i].x2) r[i] = sum[max(T[i].x1 , T[i].x2)] - 1;
else r[i] = sum[T[i].x1 + 1];
}
memset(sum , 0 , sizeof(sum));
for(int i = 1 ; i <= d ; i++) {
sum[min(T[i].y1 , T[i].y2)]++;
}
for(int i = 1 ; i <= m ; i++) {
sum[i] += sum[i - 1];
}
for(int i = 1 ; i <= d ; i++) {
if(T[i].y1 != T[i].y2) t[i] = sum[min(T[i].y1 , T[i].y2)] - 1;
else t[i] = sum[T[i].y1 - 1];
}
memset(sum , 0 , sizeof(sum));
for(int i = 1 ; i <= d ; i++) {
sum[max(T[i].y1 , T[i].y2)]++;
}
for(int i = m ; i >= 1 ; i--) {
sum[i] += sum[i + 1];
}
for(int i = 1 ; i <= d ; i++) {
if(T[i].y1 != T[i].y2) b[i] = sum[max(T[i].y1 , T[i].y2)] - 1;
else b[i] = sum[T[i].y1 + 1];
}
int flag = 0;
for(int i = 1 ; i <= d ; i++) {
//cout << l[i] << ' ' << r[i] << ' ' << t[i] << ' ' << b[i] << endl;
if(cntl == l[i] && cntr == r[i] && cntt == t[i] && cntb == b[i]) {
flag = 1;
cout << i << endl;
break;
}
}
if(!flag) cout << -1 << endl;
return 0;
}

D. Multicolored Cars (优先队列)

题解:可用优先队列辅助一下具体看一下代码挺好理解的。一旦出现出现次数最小的颜色小于A直接pop出去。

#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
const int M = 1e6 + 10;
int cnt[M] , vis[M];
struct TnT {
int num;
TnT() {}
TnT(int num):num(num) {}
bool operator <(const TnT &a) const {
return cnt[num] > cnt[a.num];
}
};
priority_queue<TnT> q;
int main() {
int n , A;
scanf("%d%d" , &n , &A);
int count = 0 , flag = 1;
memset(vis , 0 , sizeof(vis));
for(int i = 1 ; i <= n ; i++) {
int c;
scanf("%d" , &c);
if(c == A) count++;
else {
cnt[c]++;
if(cnt[c] > count && !vis[c]) q.push(c) , vis[c] = 1;
else vis[c] = 1;
}
while(!q.empty()) {
TnT gg = q.top();
if(cnt[gg.num] >= count) break;
q.pop();
}
if(q.empty()) flag = 0;
}
if(!flag) printf("-1\n");
else {
if(q.empty()) printf("-1\n");
else printf("%d\n" , q.top().num);
}
return 0;
}

E. Card Game Again(思维+二分)

题解:现将k因式分解然后拿因式的和求前缀显然是递增的然后遍历一遍向前二分

#include <iostream>
#include <cstring>
using namespace std;
const int M = 1e5 + 10;
typedef long long ll;
ll gcd(ll a , ll b) {
return (b <= 0) ? a : gcd(b , a % b);
}
struct dig {
ll num;
int sum;
};
struct TnT {
int Size;
dig a[64];
TnT():Size(0) {
memset(a , 0 , sizeof(a));
}
TnT operator +=(const TnT &b) {
for(int i = 0 ; i < 64 ; i++) {
a[i].sum += b.a[i].sum;
}
return (*this);
}
TnT operator -(const TnT &b) {
for(int i = 0 ; i < 64 ; i++) {
a[i].sum -= b.a[i].sum;
}
return (*this);
}
}s , pre[M];
void getTnT(ll x , TnT &gg) {
gg.a[gg.Size].num = 1 , gg.a[gg.Size].sum++;
gg.Size++;
ll i;
for(i = 2 ; i * i <= x ; i++) {
if(x % i == 0) {
gg.a[gg.Size].num = i;
while(!(x % i)) x /= i , gg.a[gg.Size].sum++;
gg.Size++;
}
}
if(x >= i) gg.a[gg.Size].num = x , gg.a[gg.Size].sum++ , gg.Size++;
}
void getTnT_arr(ll x , TnT &gg) {
int len = s.Size;
gg.a[0].num = 1 , gg.a[0].sum++;
for(int i = 1 ; i < len ; i++) {
if(x % s.a[i].num == 0) {
gg.a[i].num = s.a[i].num;
while(!(x % s.a[i].num)) x /= s.a[i].num , gg.a[i].sum++;
}
else gg.a[i].num = s.a[i].num , gg.a[i].sum = 0;
}
gg.Size = len;
}
ll arr[M];
int cau(int pos , int ed) {
TnT gl = pre[ed];
TnT gg = gl - pre[pos - 1];
int flag = 0;
for(int i = 0 ; i < s.Size ; i++) {
if(gg.a[i].sum < s.a[i].sum) {
flag = 1;
break;
}
}
return flag;
}
int binsearch(int l , int r , int ed) {
int mid = (l + r) >> 1;
int ans = 0;
while(l <= r) {
mid = (l + r) >> 1;
if(cau(mid , ed)) r = mid - 1;
else {
ans = mid;
l = mid + 1;
}
}
return ans;
}
int main() {
int n;
ll k;
scanf("%d%lld" , &n , &k);
getTnT(k , s);
pre[0].Size = s.Size;
for(int i = 1 ; i <= n ; i++) {
scanf("%lld" , &arr[i]);
arr[i] = gcd(arr[i] , k);
getTnT_arr(arr[i] , pre[i]);
pre[i] += pre[i - 1];
}
ll ans = 0;
for(int i = 1 ; i <= n ; i++) {
int pos = binsearch(1 , i , i);
ans += pos;
}
printf("%lld\n" , ans);
return 0;
}

F. Level Generation(三分)

题解:主要还是推一下公式一共有n个点,有k个点是任意联通的那么显然有n-k个点是单连通的那么n-k个单连通的点贡献的边数是(n-k)条边。k个点最多能连接的边的个数是min(n-k(由于要求桥的个数要超过总边数的一半),k*(k-1)/2(k个点最多能连接的边的个数)),这个自行理解一下。然后我们可以发现边的贡献是

n-k+min(n-k,k*(k-1)/2)。像这种有单峰或单谷的函数可以利用三分来求最值

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long ll;
ll n;
bool cau(ll k) {
if(k * (k - 1) / 2 > n - k) return true;
else return false;
}
ll ternsearch(ll l , ll r) {
ll mid = (l + r) >> 1;
ll sum = 0;
if(cau(mid)) sum = 2 * n - 2 * mid;
else sum = n - mid + mid * (mid - 1) / 2;
while(l <= r) {
mid = (l + r) >> 1;
ll midl = (l + mid) >> 1;
ll midr = (r + mid) >> 1;
ll now = 0 , sum1 = 0 , sum2 = 0;
if(cau(mid)) now = 2 * n - 2 * mid;
else now = n - mid + mid * (mid - 1) / 2;
sum = max(sum , now);
if(cau(midl)) sum1 = 2 * n - 2 * midl;
else sum1 = n - midl + midl * (midl - 1) / 2;
sum = max(sum1 , sum);
if(cau(midr)) now = 2 * n - 2 * midr;
else now = n - midr + midr * (midr - 1) / 2;
sum = max(sum2 , sum);
if(cau(midl) && cau(midr)) r = mid - 1;
else if(!cau(midl) && !cau(midr)) l = mid + 1;
else {
if(sum1 < sum2) r = midr - 1;
else l = midl + 1;
}
}
return sum;
}
int main() {
int q;
scanf("%d" , &q);
while(q--) {
scanf("%lld" , &n);
printf("%lld\n" , ternsearch(1 , n));
}
return 0;
}

codeforces Educational Codeforces Round 24 (A~F)的更多相关文章

  1. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  2. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  3. codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers

    题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组 ...

  4. Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph

    E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...

  5. Codeforces Educational Codeforces Round 3 D. Gadgets for dollars and pounds 二分,贪心

    D. Gadgets for dollars and pounds 题目连接: http://www.codeforces.com/contest/609/problem/C Description ...

  6. Codeforces Educational Codeforces Round 3 E. Minimum spanning tree for each edge 树上倍增

    E. Minimum spanning tree for each edge 题目连接: http://www.codeforces.com/contest/609/problem/E Descrip ...

  7. codeforces Educational Codeforces Round 16-E(DP)

    题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...

  8. Codeforces Educational Codeforces Round 15 D. Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. Codeforces Educational Codeforces Round 15 C. Cellular Network

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. 反应式微服务框架Flower

    Flower是一个构建在Akka上的反应式微服务框架,开发者只需要针对每一个细粒度的业务功能开发一个Service服务,并将这些Service按照业务流程进行可视化编排,即可得到一个反应式系统. 即时 ...

  2. DataOps系列丨数据的“资产负债表”与“现状”

    作者:DataPipeline CEO 陈诚 <跨越鸿沟>的作者Geoffrey Moore曾说“没有数据,运营企业就像一个又聋又瞎的人在高速上开车一样”.数据的价值从未像现在这样被企业重 ...

  3. Ubuntu 磁盘挂载错误

    一.错误 报错原因: 在删除或者复制移动时,磁盘或者u盘等外接硬件设备,忽然掉落(断掉,接口松动),在次挂载磁盘时就会出现错误 错误日志: $MFTMirr does not match $MFT ( ...

  4. 高性能MySQL之基础架构

    一.背景 为什么我们需要先学习MYSQL的基础架构先呢? 原因很简单,当我们需要了解一件事物的时候,我们只有站在宏观的层面,才能层层剥丝抽茧的去理解问题.举个例子,我们要看一个框架的源码,一开始就想进 ...

  5. Jquery.form异步上传文件常见问题解决

    Jquery.form常用方法我就不多说,主要说一下在使用过程中碰到的问题 1.提示 “xxxx” is not define 或者"xxx" is not a function ...

  6. 9个tcpdump使用实例

    tcpdump能帮助我们捕捉并保存网络包,保存下来的网络包可用于分析网络负载情况,包可通过tcpdump命令解析,也可以保存成后缀为pcap的文件,使用wireshark等软件进行查看. 以下将给出9 ...

  7. Web很脆弱,SQL注入要了解

    SQL注入 所谓SQL注入,就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令. 通过一下的例子更形象的了解SQL注入: 有一个Login ...

  8. Multiple dex files define Lokhttp3/internal/wsWebSocketProtocol

    Multiple dex files define Lokhttp3/internal/wsWebSocketProtocol 老套路,先晒图 图一:如题,在编译打包时遇到了如上错误,很明显这是一个依 ...

  9. SQLServer数据库处于恢复挂起状态的解决办法

    一.总结 如果数据库处于一个恢复挂起的状态,并且对数据库做脱机和分离的操作,报出数据库文件不可访问的错误,可能是因为数据库的数据文件和日志文件在数据库正常连接的情况下,文件所在的磁盘脱机了,导致数据库 ...

  10. JVM调优前戏之JDK命令行工具---jhat

    在JDK的命令行中,一般开发人员最耳熟能详的肯定就是java,javac,javap等常用命令,不过在jdk/bin下还有许多其他的命令行工具,它们被用来监测JVM运行时的状态,下面我们来详细解读一下 ...