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. k8s集群搭建及对一些组件的简单理解(二)

    背景 前面写了一篇,k8s集群搭建及对一些组件的简单理解(一),主要讲了下背景和对一些组件的理解. 今天讲一下正式的安装,有网环境的,后续再说下无外网环境纯内网的. k8s集群节点.组件 控制面节点, ...

  2. 【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 ...

  3. AT_abc317_f 题解

    调了一小时结果发现爆 long long 了. 考虑数位 dp,具体来说,设计状态 \(dp_{i,r_1,r_2,r_3,mx_1,mx_2,mx3_,c_1,c_2,c_3}\) 表示当前考虑到第 ...

  4. 1. 介绍一下 CSS 的盒子模型?

    1. 盒模型: 内容(content).填充(padding).边界(margin). 边框(border) 2. 类型: IE 盒子模型.标准 W3C 盒子模型: 3. 两种盒模型的主要区别是:标准 ...

  5. 原创软件 | 系统服务工具箱原创软件(587KB)--基于aardio开发的第一个程序

    1 系统服务工具箱简介 该软件是我使用aardio开发的第一个程序,它集成了多个系统常用的快捷键,无需记住各种命令就能快捷使用cmd管理员.计算机管理.控制面板.组策略.注册表.服务.任务管理.卸载程 ...

  6. 经典面试题函数柯里化: add(1)(2)(3) = 6

    function currying() { const args = Array.prototype.slice.call(arguments); const inner = function () ...

  7. oeasy教您玩转vim - 28 - 水平移动

    ​ 水平移动 回忆上节课内容 根据扩展名我们可以设置某些特定类型文件的配置 相关文件类型的设置放在相应的文件夹里 文件类型缩进文件夹 /usr/share/vim/vim81/indent/ 文件类型 ...

  8. oeasy教您玩转vim - 40 - # 复制粘贴

    ​ 复制粘贴 回忆上节课内容 我们上次的内容是粘贴 小写p意味着在光标下面或者后面粘贴 大写P意味着在光标上面或者前面粘贴 p的意思是放上去,就是put 把什么放上去呢? 把 reg 中 " ...

  9. 题解:AT_abc352_d [ABC352D] Permutation Subsequence

    虽然比赛没打,但是想来水估值发表思路. 题意 给你一个 \(1\sim n\) 的排列,让你从中找一段长为 \(k\) 的子序列,使得这个子序列中的元素排序后数值连续. 分析 题意转换一下,先用结构体 ...

  10. openEuler 安装 DocekrCE

    就个人而言,openEuler 算是不错的国产化操作系统."一脉传承"自redhat让实际的使用体验非常丝滑.软件源都是国内的,开箱即用,漏洞的补丁发的也挺及时.美中不足的是貌似 ...