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. format( )函数

    在Python中,DETAIL_URL.format(id=id) 是一个字符串格式化的表达式.它通常用于根据一个已定义的字符串模板 DETAIL_URL 来生成一个新的字符串.在这个模板中,会包含一 ...

  2. ClickHouse介绍(三)MergeTree系列表引擎

    MergeTree系列表引擎 ClickHouse中最核心的引擎当属MergeTree系列引擎,其中基础表引擎为MergeTree,常用的表引擎还有ReplacingMergeTree.Summing ...

  3. 一次STM32进入HardFault_Handler 的解决情况

    STM32进入HardFault_Handler调试 --- title: STM32进入HardFault_Handler调试 date: 2020-06-18 10:26:48 categorie ...

  4. PyTorch程序练习(二):循环神经网络的PyTorch实现

    一.RNN实现 结构原理 代码实现 import torch import torch.nn as nn class RNN(nn.Module): def __init__(self, input_ ...

  5. 【AppStore】一文让你学会IOS应用上架Appstore

    前言 咱们国内现在手机分为两类,Android手机与苹果手机,现在用的各类APP,为了手机的使用安全,避免下载到病毒软件,官方都极力推荐使用手机自带的应用商城进行下载,但是国内Android手机品类众 ...

  6. 跟我一起学习和开发动态表单系统-前端用vue、elementui实现方法(3)

    基于 Vue.Element UI 和 Spring Boot + MyBatis 的动态表单系统前端实现解析 在现代企业信息系统中,动态表单是一种非常常见的功能.它可以根据业务需求灵活地调整表单结构 ...

  7. package-lock.json 文件

    今天有同事找到我说,本地js 编译不过,编译不过的代码如下 const host = window?.location?.host || 'localhost'; 是option chaining, ...

  8. JDK各个版本汇总

    JDK1.4 正则表达式,异常链,NIO,日志类,XML解析器,XLST转换器 JDK1.5 自动装箱.泛型.动态注解.枚举.可变长参数.遍历循环 JDK1.6 提供动态语言支持.提供编译API和卫星 ...

  9. JavaScript -- 数据类型 --手稿

  10. 洛谷·P1130

    #include<iostream> #include<utility> using namespace std; typedef long long ll; #define ...