EOJ Monthly 2017.12 A B C D
// 因为是中文题面就偷一次懒不写题意啦QAQ
// 各种大作业然后又要期末还不知道什么时候能补题QAQ
A. 唐纳德先生和假骰子
直接模拟
#include <bits/stdc++.h>
using namespace std;
int a[6], b[6], cnt[20];
typedef long long LL;
int main() {
int p;
scanf("%d", &p);
for (int i = 0; i < 6; ++i) scanf("%d", &a[i]);
for (int i = 0; i < 6; ++i) scanf("%d", &b[i]);
for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 6; ++j) {
++cnt[(a[i]+b[j]) % p];
}
}
if (p == 3) {
if (cnt[0] == 12 && cnt[1] == 12 && cnt[2] == 12) puts("YES");
else puts("NO");
}
else {
if (cnt[0] == 9 && cnt[1]==9 && cnt[2]==9 && cnt[3]==9) puts("YES");
else puts("NO");
}
return 0;
}
B. 在哈尔滨的寒风中
容易发现当棋盘大于等于\(3\times 5\)时马可以到达任何地方,其他情况分类讨论一下即可。
// 一开始不知道怎么的理解成了马步只有\(1\times 2\)而漏了\(2\times 1\),然后整个棋局中的点就分成了四类,很高兴地交了结果wa了还纳闷的半天
// 偷懒写了个dfs(?)而没有去数小的几种情况还是原谅我吧...
#include <bits/stdc++.h>
int dr[8][2] = {{-1,-2}, {-2, -1}, {-2, 1} ,{-1, 2}, {1, 2}, {2,1}, {2,-1}, {1,-2}};
using namespace std;
typedef long long LL;
LL n,m;
int c[10][10];
LL C(LL x, int) { return x * (x-1) / 2; }
void dfs(int x, int y, int col) {
c[x][y] = col;
for (int i = 0; i < 8; ++i) {
int xx = x + dr[i][0], yy = y +dr[i][1];
if (xx <= 0 || xx > n || yy <= 0 || yy > m) continue;
if (!c[xx][yy]) dfs(xx, yy, col);
}
}
int cnt[100];
int main() {
scanf("%lld%lld", &n, &m);
LL ans=0;
if (n > m) swap(n, m);
if (n == 1) ans = 0;
else if (n == 2) {
LL n1,n2,n3,n4;
n1=n2=n3=n4 = (n/2)*(m/2);
if (m&1) ++n1,++n2;
ans = C(n1,2)*2+C(n3,2)*2;
}
else if (n == 3 || n == 4) {
if (m >= 5) ans = C(n*m, 2);
else {
int tot = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (!c[i][j]) dfs(i, j, ++tot);
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
++cnt[c[i][j]];
}
}
for (int i = 1; i <= tot; ++i) {
ans += C(cnt[i], 2);
}
}
}
else ans = C(n*m,2);
printf("%lld\n", ans);
return 0;
}
C. 易位构词
按字母出现次数排个序,然后整体循环右移 (出现最多的字母出现的位数) 那么多位,然后再按下标扔回去。
很合理。
// 比赛时没做出来,一开始一直在想最大流...
// 题解还是强啊
// 注意排序的时候不仅要按次数还要按字母本身,因为目的是要让一块一块靠在一起
#include <bits/stdc++.h>
#define maxn 100010
using namespace std;
int cnt[256];
char s[maxn], ss[maxn], ans[maxn];
struct node {
char c; int p;
bool operator < (const node& nd) const {
return cnt[c] > cnt[nd.c] || (cnt[c] == cnt[nd.c] && c < nd.c);
}
}a[maxn];
int main() {
scanf("%s", s);
int n = strlen(s);
for (int i = 0; i < n; ++i) a[i] = {s[i], i}, ++cnt[s[i]];
sort(a, a+n);
char mx = a[0].c;
int i = 0;
for (; i < n; ++i) if (a[i].c != mx) break;
int num = i;
if ((num<<1) > n) puts("impossible");
else {
for (int i = 0; i < n; ++i) ss[(i+num)%n] = a[i].c;
for (int i = 0; i < n; ++i) ans[a[i].p] = ss[i];
ans[n] = '\0';
puts(ans);
}
return 0;
}
D. 唐纳德和他的数学老师
// 开这道题的时候过的才十个人出头,读了一遍下来觉得这题十分熟悉...
// 然后因为数组大小的问题RE了3发...
#include <bits/stdc++.h>
#define maxn 1010
using namespace std;
typedef long long LL;
int tot, prime[maxn], a[3010], n, match[1000010], ne[3010], pp;
bool used[1000010], check[maxn];
struct Edge {
int to, ne;
Edge(int _to=0, int _ne=0) : to(_to), ne(_ne) {}
}edge[3000010];
void add(int u, int v) {
edge[tot] = Edge(v, ne[u]);
ne[u] = tot++;
}
void init() {
for (int i = 2; i <= 1000; ++i) {
if (!check[i]) {
prime[pp++] = i;
}
for (int j = 0; j < pp; ++j) {
if (i * prime[j] > 1000) break;
check[i * prime[j]] = true;
if (i % prime[j] == 0) break;
}
}
}
bool find(int u) {
for (int i = ne[u]; ~i; i = edge[i].ne) {
int v = edge[i].to;
if (used[v]) continue;
used[v] = true;
if (!match[v] || find(match[v])) {
match[v] = u;
return true;
}
}
return false;
}
int main() {
init();
scanf("%d", &n);
tot = 0; memset(ne, -1, sizeof ne);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
int temp = a[i];
for (int j = 0; j < pp; ++j) {
if (temp < prime[j]) break;
if (temp % prime[j] == 0) add(i, prime[j]);
while (temp % prime[j] == 0) temp /= prime[j];
}
if (temp != 1) add(i, temp);
}
for (int i = 1; i <= n; ++i) {
memset(used, 0, sizeof used);
if (!find(i)) { cout << i-1 << endl; return 0; }
}
cout << n << endl;
return 0;
}
EOJ Monthly 2017.12 A B C D的更多相关文章
- Gitlab一键端的安装汉化及问题解决(2017/12/14目前版本为10.2.4)
Gitlab的安装汉化及问题解决 一.前言 Gitlab需要安装的包太TM多了,源码安装能愁死个人,一直出错,后来发现几行命令就装的真是遇到的新大陆一样... ... 装完之后感觉太简单,加了汉化补丁 ...
- EOJ Monthly 2019.2 题解(B、D、F)
EOJ Monthly 2019.2 题解(B.D.F) 官方题解:https://acm.ecnu.edu.cn/blog/entry/320/ B. 解题 单测试点时限: 2.0 秒 内存限制: ...
- 【2017.12.12】deepin安装U盘制作,支持 BIOS+UEFI,deepin_Recovery+Win PE
U盘要求为 FAT32,MBR分区表 如果需要放 4GB 大文件,可以分两个分区,第一分区FAT32格式,放启动相关文件,第二个分区用 NTFS 格式,放其它资料. 最新 Win10 支持显示 U盘 ...
- 2017.12.21-JQuery
作业:密码加强验证 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> & ...
- 2017.12.25 Mybatis物理分页插件PageHelper的使用(二)
参考来自: 官方文档的说明:https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToUse.md 上篇博客 ...
- [LOJ#6259]「CodePlus 2017 12 月赛」白金元首与独舞
[LOJ#6259]「CodePlus 2017 12 月赛」白金元首与独舞 试题描述 到河北省 见斯大林 / 在月光下 你的背影 / 让我们一起跳舞吧 うそだよ~ 河北省怎么可能有 Stalin. ...
- java一周学习记录(2017/12/2)
姓名:Danny 日期:2017/12/2 周日 周一 周二 周三 周四 周五 周六 所花时间 120 150 190 150 180 28 ...
- 【EOJ Monthly 2018.2 (Good bye 2017)】
23333333333333333 由于情人节要回家,所以就先只放代码了. 此题是与我胖虎过不去. [E. 出老千的 xjj] #include<cstdio> #include<c ...
- 2017.12.7 URAT 串口通信
波特率就是发送二进制数据位的速率, 习惯上用 baud 表示, 即我们发送一位二进制数据的持续时间=1/baud. 在通信之前, 单片机 1 和单片机 2 首先都要明确的约定好它们之间的通信波特率, ...
随机推荐
- 【PHP】详解 $_SERVER 函数中QUERY_STRING和REQUEST_URI、SCRIPT_NAME、PHP_SELF区别
实例:1.http://localhost/index.php/Home/Home/index.html $_SERVER['QUERY_STRING'] = ""; $_SERV ...
- mysql中的FROM_UNIXTIME()函数和UNIX_TIMESTAMP()函数
unix_timestamp 是时间戳,可以用数据库里的存储时间数据的字段 from_unixtime 是将时间戳格式化为你想要时间
- Python9-MySQL数据库安装及基本操作-day42
MySQL 单机程序(自己DB) 单机程序(共用DB)MySQL:用于管理文件的一个软件 -服务端软件 -socket服务端 -本地文件操作 -解析指令[SQL语句] -客户端软件(各种各样) -so ...
- (转)curl常用命令
本文转自 http://www.cnblogs.com/gbyukg/p/3326825.html 下载单个文件,默认将输出打印到标准输出中(STDOUT)中 curl http://www.cent ...
- 【高精度】模板 (C++)
//n为长度 1.高精加 复杂度:O(n) #include<iostream> #include<cstring> #include<algorithm> usi ...
- HDU5952 Counting Cliques 暴搜优化
一.前言 这题看上去相当唬人(NPC问题),但是 因为限制了一些条件,所以实际上并没有太唬人. 二.题目 给你一个图,要求你找出数量为S的团的数量. 三.题解 暴搜,再加上一些玄学优化. 优化1:使用 ...
- ERROR L105: PUBLIC REFERS TO IGNORED SEGMENT 的解决办法
今天接着写一个单片机程序,出现这个问题,我仔细查看每一句语句,发现逻辑上没有错误,但就是出现这个问题,不能生成目标文件: *** ERROR L107: ADDRESS SPACE OVERFLOW ...
- D3DXCreateTextureFromFile
HRESULT D3DXCreateTextureFromFile( __in LPDIRECT3DDEVICE9 pDevice, __in LPCTSTR pSrcFile, __out LPDI ...
- Django之session验证的三种姿势
一.什么是session session是保存在服务端的键值对,Django默认支持Session,并且默认是将Session数据存储在数据库中,即:django_session 表中. 二.FVB中 ...
- CLOUDSTACK FOR HYPER-V
原文地址:http://zhu.vn/archives/1040 我这里是内网测试环境,宿主机为Server 2012R2 ,虚拟化技术为HYPER-V,域环境来的(不是域环境玩不了). 先给宿主机安 ...