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. Prometheus监控系统(三)Prometheus与Grafana集成

    1. Prometheus和Grafana集成 Grafana是一款采用Go语言编写的开源应用,主要用于大规模指标数据的可视化展现,是网络架构和应用分析中最流行的时序数据展示工具.目前已支持绝大部分常 ...

  2. vim中ctags 的使用

    --- title: vim中ctags 的使用 EntryName: vim-config-with-ctags date: 2020-08-19 11:17:38 categories: tags ...

  3. 详细讲解 Keil Pack Installer,以及通过 Keil 官网获取 Pack

    前言 大家好,我是梁国庆. 收到粉丝留言,说 Keil 安装 Pack 不太明白,可不可以详细演示一下? 当然可以有,直接视频+文章全部安排,我就是宠粉. PS:第一次录视频有些紧张,见谅哈. 微信视 ...

  4. Salt安装部署

    Salt安装部署 一:salt简介 ​ 早期运维人员会根据自己的生产环境来写特定脚本完成大量重复性工作,这些脚本复杂且难以维护.系统管理员面临的问题主要是1.系统配置管理,2.远程执行命令,因此诞生了 ...

  5. 【Hive报错】java.lang.NoSuchMethodError(com.facebook.fb303.FacebookService$Client.sendBaseOneway

    Hive2.3版本 Hadoop2.7版本 执行hive命令报错: 报错内容: CONSOLE#21/03/24 17:32:54 ERROR ql.Driver: FAILED: Hive Inte ...

  6. 【ClickHouse】3:clickhouse基本操作一 用户权限管理

    背景介绍: 有三台CentOS7服务器安装了ClickHouse HostName IP 安装程序 程序端口 centf8118.sharding1.db 192.168.81.18 clickhou ...

  7. Java 数据类型的包装数据类型

    什么是包装数据类型 Java是一个面向对象的编程语言,但基本类型并不具有对象的性质,为了让基本类型也具有对象的特征,就出现了包装类型. 集合框架里面需要存储对象,不能存储基本数据类型,所以需要存储包装 ...

  8. Spring的xml和注解对比

    常用注解 bean定义 XML方式:<bean></bean> 注解方式:@Component 通用组件 @Controller(web层) @Service(service层 ...

  9. java dom4j解析xml

    jar包下载 官网地址:点我直达 将jar包导入工程 package com.cyb; import java.io.InputStream; import java.security.Message ...

  10. CF717E

    这道题属于是那种看上去很有思路,然后无从下手,写了个dfs感觉实在是不行. 后面仔细看了一下,这个题是用的构造dfs,基本是树上dfs,时间复杂度是O(V+E) 新构造的一个参数作为根,整个dfs表示 ...