0

0

Codeforces Round #234 (Div. 2)

php中文网

php中文网

发布时间:2016-06-07 15:44:27

|

1257人浏览过

|

来源于php中文网

原创

Problems # Name A inna and choose options standard input/output 1 s, 256 MB x1942 B Inna and New Matrix of Candies standard input/output 1 s, 256 MB x1556 C Inna and Huge Candy Matrix standard input/output 2 s, 256 MB x1114 D Dima and Bact

Problems

Codeforces Round #234 (Div. 2)

 

 

# Name    
A

inna and choose options

standard input/output

智谱清影
智谱清影

智谱清影是智谱AI最新推出的一款AI视频生成工具

下载
1 s, 256 MB
Codeforces Round #234 (Div. 2) Codeforces Round #234 (Div. 2) Codeforces Round #234 (Div. 2) x1942
B

Inna and New Matrix of Candies

standard input/output

1 s, 256 MB
Codeforces Round #234 (Div. 2) Codeforces Round #234 (Div. 2) Codeforces Round #234 (Div. 2) x1556
C

Inna and Huge Candy Matrix

standard input/output

2 s, 256 MB
Codeforces Round #234 (Div. 2) Codeforces Round #234 (Div. 2) Codeforces Round #234 (Div. 2) x1114
D

Dima and Bacteria

standard input/output

2 s, 256 MB
Codeforces Round #234 (Div. 2) Codeforces Round #234 (Div. 2) Codeforces Round #234 (Div. 2) x371
E

Inna and Binary Logic

standard input/output

3 s, 256 MB
Codeforces Round #234 (Div. 2) Codeforces Round #234 (Div. 2) Codeforces Round #234 (Div. 2) x169

A题:直接暴力枚举每种情况即可。水题

B题:记录下S,G的距离,每种距离只要一次,开个vis数组标记,最后遍历一遍看又几个即可

C题:模拟旋转即可。

D题:并查集+floyd,把w=0的边的点并查集处理,判断同种类是否都在一个集合内,不是就No,剩下的就利用floyd求出最短路即可。

E题:位运算,每个数字对应的每个位向左和向右延生,这个区间内向下的那个三角形区间一定是会增加(1

代码:

A题:

#include <stdio.h>
#include <string.h>

int t, n;
char str[15];
char save[15][15];

bool judge(int a, int b) {
    int i, j;
    for (i = 0; i < a; i++) {
        for (j = 0; j < b; j++)
            save[i][j] = str[i * b + j];
    }
    for (i = 0; i < b; i++) {
        for (j = 0; j < a; j++) {
            if (save[j][i] != 'X') break;
        }
        if (j == a) return true;
    }
    return false;
}

int main() {
    scanf("%d", &t);
    while (t--) {
        scanf("%s", str);
        int ans = 0;
        if (judge(1, 12)) ans++;
        if (judge(2, 6)) ans++;
        if (judge(3, 4)) ans++;
        if (judge(4, 3)) ans++;
        if (judge(6, 2)) ans++;
        if (judge(12, 1)) ans++;
        printf("%d", ans);
        if (judge(1, 12)) printf(" 1x12");
        if (judge(2, 6)) printf(" 2x6");
        if (judge(3, 4)) printf(" 3x4");
        if (judge(4, 3)) printf(" 4x3");
        if (judge(6, 2)) printf(" 6x2");
        if (judge(12, 1)) printf(" 12x1");
        printf("\n");
    }
    return 0;
}

B题:

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 1005;
int n, m, i, j, vis[N];
char g[N][N];

int main() {
    scanf("%d%d", &n, &m);
    for (i = 0; i < n; i++)
        scanf("%s", g[i]);
    for (i = 0; i < n; i++) {
        int G, S;
        for (j = 0; j < m; j++) {
            if (g[i][j] == 'G') G = j;
            if (g[i][j] == 'S') S = j;
        }
        if (S < G) {
            printf("-1\n");
            return 0;
        }
        int d = S - G;
        vis[d] = 1;
    }
    int ans = 0;
    for (int i = 0; i <= 1000; i++)
        if (vis[i]) ans++;
    printf("%d\n", ans);
    return 0;
}

C题:

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int n, m, x, y, z, p, i, j;
struct Point {
    int x, y;
} po[100005];

void at(Point &a) {
    int x = a.x, y = a.y;
    a.y = n - x + 1;
    a.x = y;
}

void ht(Point &a) {
    int x = a.x, y = a.y;
    a.y = m - y + 1;
    a.x = x;
}

void ct(Point &a) {
    int x = a.x, y = a.y;
    a.y = x;
    a.x = m - y + 1;
}

int main() {
    scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &p);
    x %= 4;
    y %= 2;
    z %= 4;
    for (i = 0; i < p; i++)
        scanf("%d%d", &po[i].x, &po[i].y);
    for (j = 0; j < x; j++) {
        for (i = 0; i < p; i++) {
            at(po[i]);
        }
        int t = n; n = m; m = t;
    }
    for (j = 0; j < y; j++) {
        for (i = 0; i < p; i++) {
            ht(po[i]);
        }
    }
    for (j = 0; j < z; j++) {
        for (i = 0; i < p; i++) {
            ct(po[i]);
        }
        int t = n; n = m; m = t;
    }
    for (i = 0; i < p; i++)
        printf("%d %d\n", po[i].x, po[i].y);
    return 0;
}

D题:

#include <stdio.h>
#include <string.h>
#include <vector>
#define INF 0x3f3f3f3f
#define min(a,b) ((a)<(b)?(a):(b))
const int N = 100005;
int n, m, K, type[N], i, j, k;
int f[505][505], fa[N], c[505];

int find(int x) {
    if (x == fa[x])
        return x;
    x = find(fa[x]);
}

int main() {
    scanf("%d%d%d", &n, &m, &K);
    int tn = 0;
    memset(f, INF, sizeof(f));
    for (i = 1; i <= n; i++)
        fa[i] = i;
    for (i = 1; i <= K; i++) {
        f[i][i] = 0;
        scanf("%d", &c[i]);
        for (j = 0; j < c[i]; j++) {
            type[++tn] = i;
        }
    }
    int u, v, w;
    while (m--) {
        scanf("%d%d%d", &u, &v, &w);
        if (type[u] != type[v] && f[type[u]][type[v]] > w) {
            f[type[u]][type[v]] = w;
            f[type[v]][type[u]] = w;
        }
        if (w == 0) {
            int pu = find(u);
            int pv = find(v);
            if (pu != pv)
                fa[pv] = pu;
        }
    }
    for (i = 2; i <= n; i++) {
        int u = i - 1, v = i;
        if (type[u] == type[v]) {
            if (find(u) != find(v)) {
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    for (k = 1; k <= K; k++) {
        for (i = 1; i <= K; i++) {
            for (j = 1; j <= K; j++) {
                f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
            }
        }
    }
    for (i = 1; i <= K; i++) {
        for (j = 1; j < K; j++) {
            if (f[i][j] == INF) f[i][j] = -1;
            printf("%d ", f[i][j]);
        }
        if (f[i][K] == INF) f[i][K] = -1;
        printf("%d\n", f[i][K]);
    }
    return 0;
}

E题:

#include <stdio.h>
#include <string.h>

const int N = 100005;
const int M = 20;
int n, m, i, j, b;
int a[N][M];
__int64 sum, mi[32];

int main() {
    mi[0] = 1;
    for (i = 1; i < 32; i++)
        mi[i] = mi[i - 1] * 2;
    sum = 0;
    scanf("%d%d", &n, &m);
    int num;
    for (i = 1; i <= n; i++) {
        scanf("%d", &num);
        for (b = 0; b <= 18; b++) {
            if (num&mi[b]) {
                a[i][b] = 1;
            }
        }
    }
    __int64 k = 0;
    for (b = 0; b <= 18; b++) {
        for (i = 1; i <= n; i++) {
            if (a[i][b]) k++;
            else {
                sum += mi[b] * k * (k + 1) / 2;
                k = 0;
            }
        }
        if (k != 0) {
            sum += mi[b] * k * (k + 1) / 2;
                k = 0;
        }
    }
    int p;
    __int64 v;
    while (m--) {
        scanf("%d%I64d", &p, &v);
        __int64 ans1 = 0, ans2 = 0;
        for (b = 0; b <= 18; b++) {
            if (a[p][b]) sum -= mi[b];
            if (a[p][b] && (v&mi[b]) == 0) {
                __int64 l = p, r = p;
                while (a[l - 1][b]) {
                    l--;
                }
                while (a[r + 1][b]) {
                    r++;
                }
                ans1 += mi[b] * ((p - l) * (r - p) + (p - l) + (r - p));
                a[p][b] = 0;
            }
            else if ((v&mi[b]) && a[p][b] == 0) {
                int l = p, r = p;
                while (a[l - 1][b]) {
                    l--;
                }
                while (a[r + 1][b]) {
                    r++;
                }
                ans2 += mi[b] * ((p - l) * (r - p) + (p - l) + (r - p));
                a[p][b] = 1;
            }
        }
        sum = sum - ans1 + ans2 + v;
        printf("%I64d\n", sum);
    }
    return 0;
}


热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
pixiv网页版官网登录与阅读指南_pixiv官网直达入口与在线访问方法
pixiv网页版官网登录与阅读指南_pixiv官网直达入口与在线访问方法

本专题系统整理pixiv网页版官网入口及登录访问方式,涵盖官网登录页面直达路径、在线阅读入口及快速进入方法说明,帮助用户高效找到pixiv官方网站,实现便捷、安全的网页端浏览与账号登录体验。

1044

2026.02.13

微博网页版主页入口与登录指南_官方网页端快速访问方法
微博网页版主页入口与登录指南_官方网页端快速访问方法

本专题系统整理微博网页版官方入口及网页端登录方式,涵盖首页直达地址、账号登录流程与常见访问问题说明,帮助用户快速找到微博官网主页,实现便捷、安全的网页端登录与内容浏览体验。

334

2026.02.13

Flutter跨平台开发与状态管理实战
Flutter跨平台开发与状态管理实战

本专题围绕Flutter框架展开,系统讲解跨平台UI构建原理与状态管理方案。内容涵盖Widget生命周期、路由管理、Provider与Bloc状态管理模式、网络请求封装及性能优化技巧。通过实战项目演示,帮助开发者构建流畅、可维护的跨平台移动应用。

213

2026.02.13

TypeScript工程化开发与Vite构建优化实践
TypeScript工程化开发与Vite构建优化实践

本专题面向前端开发者,深入讲解 TypeScript 类型系统与大型项目结构设计方法,并结合 Vite 构建工具优化前端工程化流程。内容包括模块化设计、类型声明管理、代码分割、热更新原理以及构建性能调优。通过完整项目示例,帮助开发者提升代码可维护性与开发效率。

35

2026.02.13

Redis高可用架构与分布式缓存实战
Redis高可用架构与分布式缓存实战

本专题围绕 Redis 在高并发系统中的应用展开,系统讲解主从复制、哨兵机制、Cluster 集群模式及数据分片原理。内容涵盖缓存穿透与雪崩解决方案、分布式锁实现、热点数据优化及持久化策略。通过真实业务场景演示,帮助开发者构建高可用、可扩展的分布式缓存系统。

111

2026.02.13

c语言 数据类型
c语言 数据类型

本专题整合了c语言数据类型相关内容,阅读专题下面的文章了解更多详细内容。

77

2026.02.12

雨课堂网页版登录入口与使用指南_官方在线教学平台访问方法
雨课堂网页版登录入口与使用指南_官方在线教学平台访问方法

本专题系统整理雨课堂网页版官方入口及在线登录方式,涵盖账号登录流程、官方直连入口及平台访问方法说明,帮助师生用户快速进入雨课堂在线教学平台,实现便捷、高效的课程学习与教学管理体验。

17

2026.02.12

豆包AI网页版入口与智能创作指南_官方在线写作与图片生成使用方法
豆包AI网页版入口与智能创作指南_官方在线写作与图片生成使用方法

本专题汇总豆包AI官方网页版入口及在线使用方式,涵盖智能写作工具、图片生成体验入口和官网登录方法,帮助用户快速直达豆包AI平台,高效完成文本创作与AI生图任务,实现便捷智能创作体验。

813

2026.02.12

PostgreSQL性能优化与索引调优实战
PostgreSQL性能优化与索引调优实战

本专题面向后端开发与数据库工程师,深入讲解 PostgreSQL 查询优化原理与索引机制。内容包括执行计划分析、常见索引类型对比、慢查询优化策略、事务隔离级别以及高并发场景下的性能调优技巧。通过实战案例解析,帮助开发者提升数据库响应速度与系统稳定性。

97

2026.02.12

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
JS轻松实现打地鼠游戏
JS轻松实现打地鼠游戏

共6课时 | 0.7万人学习

前端工程师必备技能—PS切图
前端工程师必备技能—PS切图

共11课时 | 1.9万人学习

JS开发验证表单教程
JS开发验证表单教程

共9课时 | 3万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号