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. 解决 Visual C++ 17.5 __cplusplus 始终为 199711L 的问题

    00. 软件环境 Visual Studio 2022, Visual C++, Version 17.5.4 01. 问题描述 在应用 https://github.com/ToniLipponen ...

  2. Jenkins从github拉取项目,github有更新,自动进行构建,实现自动集成

    使用git之前的准备工作 1. 搭建Jenkins的机器上,有安装git,配置git的安装地址,Jenkins配置Git的安装地址 2. Global Tool Configuration - > ...

  3. 在Linux驱动中使用gpio子系统

    reference: https://blog.csdn.net/shiyongyue/article/details/75103446 http://blog.rongpmcu.com/gpiozi ...

  4. Oracle常用统计

    测试, 这是测消息 1.按天 select to_char(t.STARTDATE+15/24, 'YYYY-MM-DD') as 天,sum(1) as 数量from HOLIDAY tgroup ...

  5. 【建议收藏】Go语言关键知识点总结

    容器 数组和切片 在Go语言中,数组和切片是两个基本的数据结构,用于存储和操作一组元素.它们有一些相似之处,但也有许多不同之处.下面我们详细介绍数组和切片的特点.用法以及它们之间的区别. 数组 数组是 ...

  6. T3/A40i支持Linux-5.10新内核啦,Docker、Qt、Python统统升级!

    自2021年创龙科技推出全志国产化率100%的T3/A40i工业核心板后,不到两年时间已超过800家工业客户选择创龙科技T3/A40i平台.随着客户产品的不断升级与迭代,部分"能源电力&qu ...

  7. Python性能测试框架:Locust实战教程

    01认识Locust Locust是一个比较容易上手的分布式用户负载测试工具.它旨在对网站(或其他系统)进行负载测试,并确定系统可以处理多少个并发用户,Locust 在英文中是 蝗虫 的意思:作者的想 ...

  8. gdb 根据c语言二进制文件进程号查看内部多线程任务

    C语言二进制文件 a 编译时添加了 -g (gdb 调试), 但是 gdb a 这种方式有时不容易复现一些场景.这时可以先正常启动 a, 然后根据 a 的进程号启动gdb调试. # 1. 找到程序进程 ...

  9. SqlParameter,参数化查询问题

    SqlParameter p = new SqlParameter("@pageIndex", (object)pageIndex); SqlParameter带有两个参数的构造函 ...

  10. PixiJS源码分析系列: 第一章 从最简单的例子入手

    从最简单的例子入手分析 PixiJS 源码 我一般是以使用角度作为切入点查看分析源码,例子中用到什么类,什么方法,再入源码. 高屋建瓴的角度咱也做不到啊,毕竟水平有限 pixijs 的源码之前折腾了半 ...