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和Python生成短链接服务的字符串ID
假设你想做一个像微博短链接那样的短链接服务,短链接服务生成的URL都非常短例如: http://t.cn/E70Piib, 我们应该都能想到链接中的E70Piib对应的就是存储长链接地址的数据记录的I ...
- 【PHP】常用的PHP正则表达式收集整理
匹配中文字符的正则表达式: [\u4e00-\u9fa5]评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 匹配双字节字符(包括汉字在内):[^\x00-\xff]评注:可以用来计算字符串的长度 ...
- java util - base64转换工具
测试代码 package cn.java.codec.base64; public class Test { public static void main(String[] args) { Stri ...
- JZOJ 4732. 【NOIP2016提高A组模拟8.23】函数
4732. [NOIP2016提高A组模拟8.23]函数 (Standard IO) Time Limits: 1500 ms Memory Limits: 262144 KB Detailed ...
- 解决cmd目录下pip命令不存在的问题
解决cmd目录下pip命令不存在的问题 注:pip.exe程序在Python安装目录下的scripts中1.在cmd命令中输入: 先输入:python -m ensurepip 再输入:python ...
- python学习笔记(四):生成器、内置函数、json
一.生成器 生成器是什么?其实和list差不多,只不过list生成的时候数据已经在内存里面了,而生成器中生成的数据是当被调用时才生成呢,这样就节省了内存空间. 1. 列表生成式,在第二篇博客里面我写了 ...
- 权限组件(12):自动发现项目中有别名的URL
自动发现项目中所有有别名的URL,效果如下: customer_list {'name': 'customer_list', 'url': '/customer/list/'} customer_ad ...
- git之简单入门及操作~
看了bili的教程,https://www.bilibili.com/video/av23853294?from=search&seid=3300012850779227291 特此整理下. ...
- Codeforces Round #462 (Div. 2) C. A Twisty Movement
C. A Twisty Movement time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- 12、python中的函数(高阶函数)
一.高阶函数 函数实际上也是一个对象,所以也能由变量指向一个函数对象,实际上函数名就是一个变量名.那么函数是传入变量作为参数的,如果传入的变量指向的是函数对象,这种函数就叫高阶函数. 高阶函数就是传入 ...