23 暑假友谊赛 No.4(UKIEPC 2017)

Problem A

Alien Sunset

hh,开始一眼差分,但是写寄了qwq,后来换枚举过了(Orz,但是看学长差分是能做的,我就说嘛,差分肯定能做(

说下枚举思路吧,就是把每个区间都存起来,选出自转周期的最大值为\(ma\),然后去枚举\(0 \sim ma \times 1825\),每次看枚举的这个数是否都不在给定的区间内即可,复杂度\(\mathcal{O}(Max(H_i)\times1825 \times N)\)

#include<bits/stdc++.h>

using namespace std;

struct Node{
int H,R,T;
}; int main() {
int n,mn = 1,ma = 0;
cin >> n;
vector<Node> A(n);
for(int i = 0;i < n;i ++){
cin >> A[i].H >> A[i].R >> A[i].T;
ma = max(ma, A[i].H);
} for(int i = 0;i <= ma * 1825;i ++){ bool f = true;
while(f){
for(int j = 0;j < n;j ++){
int k = i % A[j].H;
if(A[j].R < A[j].T){
if(k > A[j].R && k < A[j].T){
f = false;
break;
}
}else{
if(k < A[j].T || k > A[j].R){
f = false;
break;
}
}
}
if(f){
cout << i << '\n';
return 0;
}
}
} cout << "impossible\n"; return 0;
}

Problem C(贪心)

Cued In

推倒一下样例大概就能发现:

第一个样例:黑红黑红黑红黑粉

第三个样例:棕红棕红棕红棕红棕红棕绿黄

其实就是先把分最大打进洞,然后场上存在红球就又把分最大的捞出来,再打进红球,最后一定会存在除红球以外的所有球,这时候一一打进去即可.

#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main() {

    int n;
cin >> n;
unordered_map<string,int> col;
col["red"] = 1,col["yellow"] = 2,col["green"] = 3;
col["brown"] = 4,col["blue"] = 5,col["pink"] = 6, col["black"] = 7;
int num[8] = {0}; int ma = 0,sum = 0,rednum = 0;
for(int i = 0;i < n;i ++){
string s;
cin >> s;
rednum += (s == "red");
num[col[s]]++;
sum += col[s];
ma = max(ma, col[s]);
} if(rednum == n){
cout << "1\n";
}else{
cout << (ma + 1) * rednum + (sum - rednum) << '\n';
} return 0;
}

Problem D

Deranging Hat

展开查看

hh,这题真傻逼刚开始读题我看那翻译一直以为它说的是$A_i$项大于$B_i$项调换,结果它是说$A_i$项大于$B_i$项时要放前边输出,反正我是看了两三个翻译软件没看懂,还wa了两发,hah,但是看到别人都一连串的过了,或许,我是傻逼(?

思路就是将给的字符串排序后再还原到原字符串,然后哪项更大就放前边输出

#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int32_t main() {

    string s;
cin >> s; string str = s; sort(str.begin(), str.end()); for (int i = 0; i < str.size(); i++) { if (s[i] != str[i]) {
for (int j = i + 1; j < str.size(); j++) {
if (str[j] == s[i]) {
if (str[j] > str[i])cout << j + 1 << ' ' << i + 1 << endl;
else cout << i + 1 << ' ' << j + 1 << endl;
swap(str[j],str[i]);
break;
}
}
}
} return 0;
}

Problem E(贪心)

Education

本题就是一个排序贪心的问题,将房子按租金从小到大排序,然后学生也是人数从多到少排序,最后将学生放进房子就行(

#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

typedef pair<int,int> PII;
typedef pair<PII,int> PPI; int main() { int n,m;
cin >> n >> m;
vector<PII> s(n + 1);
vector<pair<PII,int>> p(m + 1);
for(int i = 1;i <= n;i ++) {
cin >> s[i].first;
s[i].second = i;
}
for(int i = 1;i <= m;i ++) cin >> p[i].first.first;
for(int i = 1;i <= m;i ++){
cin >> p[i].first.second;
p[i].second = i;
} std::sort(s.begin() + 1, s.end(),[](PII a,PII b){
return a.first > b.first;
});
std::sort(p.begin() + 1, p.end(),[](PPI a, PPI b){
if(a.first.second == b.first.second) return a.first.first < b.first.first;
return a.first.second < b.first.second;
}); vector<int> ans(n + 1);
vector<bool> vis(m + 1,false);
int cnt = 0;
for(int i =1;i <= n;i ++){ for(int j = 1;j <= m;j ++){
if(p[j].first.first >= s[i].first && !vis[j]){
vis[j] = true;
cnt ++;
ans[s[i].second] = p[j].second;
break;
}
}
} if(cnt != n){
cout << "impossible\n";
}else{
for(int i = 1;i <= n;i ++){
cout << ans[i] << " \n"[i == n];
}
} return 0;
}

Problem F(概率dp)

Flipping Coins

设\(dp[i][j]\)表示抛i次j个向上的概率,根据全概率公式:\(dp[i][j] = dp[i - 1][j] * 0.5 + dp[i - 1][j - 1] * 0.5\),

特别的,当\(j = (n - 1)\) 时,有\(dp[i][j] = dp[i - 1][j] * 0.5 + dp[i - 1][j + 1] * 0.5 + dp[i - 1][j - 1] * 0.5\)。

因为在\(j = (n-1)\)时,还可以是由全部面朝上的硬币得到,比如抛了一枚面朝上的硬币但最后那枚硬币面朝下,这个时候也能得到\((n-1)\)枚向上,另外概率不能直接除以2,会丢失小数.

#include<bits/stdc++.h>
using namespace std; double dp[610][610]; int main(){
ios::sync_with_stdio(0),cin.tie(0);//,cout.tie();
int n, k;
cin >> n >> k;
dp[0][0] = 1;
for(int i=1;i<=k;i++) {
for (int j = 0; j <= k; j++) {
dp[i][j] += dp[i - 1][j] * 0.5 + dp[i - 1][j - 1] * 0.5;
if(j == n-1) dp[i][j] += dp[i - 1][n] * 0.5;
}
}
double ans = 0;
for(int i=0;i<=n;i++) ans += i*dp[k][i];
printf("%.8lf",ans);
return 0;
}

Problem I

I Work All Day

就是选择一个长度使得木头被这个长度均分后剩余的边角料(?)最少,所以直接取模看哪个余数最小就选哪个长度

#include<bits/stdc++.h>
//#define int long long
#define endl '\n' using namespace std; int32_t main() {
int n;
cin >> n;
vector<int> a(n);
for (auto &i: a)cin >> i;
int m;
cin >> m;
int ans = INT_MAX;
int x = INT_MAX;
for (auto i: a) {
if (m % i < x) {
x = m % i;
ans = i;
}
}
cout << ans << endl;
return 0;
}

Problem J

Just A Minim

签到题,貌似没啥好讲的,不过要注意精度问题(

#include<bits/stdc++.h>
using namespace std; int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie();
int n;
cin >> n;
double ans = 0;
for(int i=1;i<=n;i++){
int a;
cin >> a;
if(a == 0) ans += 2;
else if(a == 1) ans += 1;
else if(a == 2) ans += 0.5;
else if(a == 4) ans += 0.25;
else if(a == 8) ans += 0.125;
else ans += 0.0625;
}
printf("%.6lf",ans);
return 0;
}

23 暑假友谊赛 No.4(UKIEPC 2017)的更多相关文章

  1. Codeforces Gym101606 A.Alien Sunset (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017) 寒假第一次组队训练赛,和学长一起训练,题目难度是3颗星,我和猪队友写 ...

  2. Codeforces Gym101606 C.Cued In (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    C Cued In 这个题是打球的.都忘了写的什么了... 代码: 1 #include<iostream> 2 #include<cstring> 3 #include< ...

  3. Codeforces Gym101606 J.Just A Minim (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    J Just A Minim 超级无敌大水题,但是被精度卡了一手,输出要精确到小数点后6位,我直接输出的... 代码: 1 #include<iostream> 2 #include< ...

  4. Codeforces Gym101606 I.I Work All Day (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    I I Work All Day 这个题就是取模找最小的. 代码: 1 #include<iostream> 2 #include<cstdio> 3 #include< ...

  5. Codeforces Gym101606 E.Education (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    E Education 这个题有点意思,就是找满足条件的最小价格里的最大值的人数,有点贪心的思想吧,一开始写错了,人群的那个不能排序,而且是最小价格里找能住下人最多的部门,让这个部门去住这个房间.在循 ...

  6. Codeforces Gym101606 D.Deranging Hat (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    D Deranging Hat 这个题简直了,本来想的是冒泡排序然后逆着输出来的,后来发现不对,因为题目上求的是最优解,而且冒泡的话,输出结果有的超出10000行了,所以就是把一开始的,排好序的字母标 ...

  7. 2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)

    A. Alien Sunset 暴力枚举答案即可. #include<cstdio> int n,i,mx; struct P{ int h,r,t; bool night(int x){ ...

  8. [寒假集训第一场]gym101606 2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)

    3星场 难度在于英文题面太难读懂了QAQ 看样例猜题意的我 博客园的c++主题真丑 A Alien Sunset \(description\) 有\(n\)个星球,每个星球自转时间不一样,所以一天的 ...

  9. 合肥学院ACM集训队第一届暑假友谊赛 B FYZ的求婚之旅 D 计算机科学家 F 智慧码 题解

    比赛网址:https://ac.nowcoder.com/acm/contest/994#question B FYZ的求婚之旅 思路: 然后用快速幂即可. 细节见代码: #include <i ...

  10. 转载:2017百度春季实习生五道编程题[全AC]

    装载至:https://blog.csdn.net/zmdsjtu/article/details/70880761 1[编程题]买帽子 时间限制:1秒空间限制:32768K度度熊想去商场买一顶帽子, ...

随机推荐

  1. python重拾基础第二天

    本节内容 列表.元祖操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 三元运算&生成式&成员运算&解压法&队列堆栈&数据类型转换 1. 列表操作 ...

  2. FFmpeg新旧接口对照使用一览

    背景 根据例程学习调用ffmpeg 库方法的时候,发现了一堆警告. main.cpp:81:37: warning: 'AVStream::codec' is deprecated [-Wdeprec ...

  3. 【路径规划】OSQP曲线平滑 公式及代码

    参考与前言 apollo 代码:https://github.com/ApolloAuto/apollo/tree/master/modules/planning/math/smoothing_spl ...

  4. ARC108C

    考虑一颗树怎么染色. 每个子节点染成边的颜色,如果与父亲节点相同,就随便染色(这条边的限制已经被父亲节点满足). 那么一定可以染色. 所以把原图跑最小生成树再按上述方法染色即可. 倘若原图不连通,那么 ...

  5. 全国DNS服务器IP大全

  6. Odoo17.0 基于企业微信的备用金和费用报销

    前面讲过了企业微信的基础应用,现在我们来看一下如何借助企业微信的审批端能力结合odoo来实现企业中的两大常规业务流程备用金和费用报销. 企业微信端设置 我们这里使用的是企业微信的原生审批流程,因此我们 ...

  7. Nuxt框架中内置组件详解及使用指南(五)

    title: Nuxt框架中内置组件详解及使用指南(五) date: 2024/7/10 updated: 2024/7/10 author: cmdragon excerpt: 摘要:本文详细介绍了 ...

  8. [oeasy]python0024_unix时间戳_epoch_localtime_asctime_PosixTime_unix纪年法

    输出时间回忆上次内容 通过搜索 我们学会 import 导入 time 了 完整写法为 asc_time = time.asctime( time.localtime( time.time())) 内 ...

  9. [rCore学习笔记 08]内核第一条指令

    了解QEMU 启动指令 qemu-system-riscv64 \ -machine virt \ -nographic \ -bios ../bootloader/rustsbi-qemu.bin ...

  10. vuex使用和场景案例

    vuex是vue提供的一个集中式状态管理器,用于对数据的集中式管理. vuex有四个重要的属性:state.mutations.actions.getters 1.vuex的使用 安装 npm ins ...