【ICPC 2021网络赛2】The 2021 ICPC Asia Regionals Online Contest (II)签到题5题
M. Addition
题意:
- 给出n,接下来三行,每行n位二进制数,分别表示符号sgn{-1,1}和a{0,1}, b{0,1}。
- 令c=a+b(a和sgn每位相乘得到数a),最后将c拆成每一位输出。
思路:
- 暴力把va和vb算出来,得到vc,然后每一位拆出来判断进位即可。(考场的时候pows用了自带的然后卡精度改了好久)
//M
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e4+10;
LL pows( LL a, LL b){if(b==0)return 1;LL ns = pows(a,b>>1);ns = ns*ns;if(b&1)ns = ns*a;return ns;
}int sgn[maxn], a[maxn], b[maxn], c[maxn];int main(){int n; cin>>n;for(int i = 0; i < n; i++)cin>>sgn[i];for(int i = 0; i < n; i++)cin>>a[i];for(int i = 0; i < n; i++)cin>>b[i];LL va = 0, vb = 0;for(int i = 0; i < n; i++) va += pows(2,i)*a[i]*sgn[i];for(int i = 0; i < n; i++) vb += pows(2,i)*b[i]*sgn[i];LL vc = va+vb;// vc=-7;// n = 4;// sgn[0]=-1; sgn[1] = -1; sgn[2] = 1; sgn[3] = 1;for(int i=0;i<n;i++){if(((vc>>i)&1)){if(sgn[i]==-1){c[i]=1;vc+=pows(2,i+1);}else{c[i]=1;}}elsec[i]=0;// cout<<vc<<'\n';if(i!=0)cout<<" ";cout<<c[i];}return 0;
}
J Leaking Roof
题意:
- 给出一个n*n的矩阵表示屋顶每块瓦片的高度,现在初始每片上都有m的雨水。
- 每片上的雨水都会均匀的流向比他低的瓦片上,求足够上时间后,所有高度0瓦片上的雨水量
思路:
- 给所有瓦片按高度排个序,然后从高到低流即可。
//J
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 550;int h[maxn][maxn];
double a[maxn][maxn];
struct node{int x, y, h; double v;};
vector<node>G;
bool cmp(node x, node y){return x.h>y.h;}int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};int main(){int n, m; cin>>n>>m;for(int i = 1; i <= n; i++){for(int j = 1; j <= n; j++){cin>>h[i][j];a[i][j] = (double)m;G.push_back({i,j,h[i][j],(double)m});}}sort(G.begin(),G.end(),cmp);for(auto x : G){int cnt = 0;for(int i = 0; i < 4; i++){int nx = x.x+dx[i], ny = x.y+dy[i];if(nx>n||ny>n||nx<1||ny<1)continue;if(h[nx][ny]<x.h){cnt++;}}for(int i = 0; i < 4; i++){int nx = x.x+dx[i], ny = x.y+dy[i];if(nx>n||ny>n||nx<1||ny<1)continue;if(h[nx][ny]<x.h){a[nx][ny] += a[x.x][x.y]/cnt;}}if(cnt!=0)a[x.x][x.y] = 0;}for(int i = 1; i <= n; i++){for(int j = 1; j <= n; j++){if(j!=1)cout<<" ";if(h[i][j]!=0)cout<<"0";else printf("%.6lf", a[i][j]);}if(i!=n)cout<<"\n";}return 0;
}
H. Set
题意:
- 定义集合S{1,2…256},给出k和r,要求构造S的k个子集I[i],满足对于任意的I[1]<I[2]<…I[r]<I[n], I[1-r并集]>=128, 且max{I}<512/r。
思路:
- 直接rand所有的子集(虽然不知道怎么证明)
#include<bits/stdc++.h>
using namespace std;
int rand(int l, int r){ return rand()%(r-l+1)+l; }
int main(){srand(time(0));int k, r; cin>>k>>r;for(int i = 1; i <= k; i++){set<int>se;while((int)se.size()<(512+r-1)/r)se.insert(rand(1,256));for(int j = 1; j <= 256; j++){cout<<se.count(j);}cout<<"\n";}return 0;
}
G Limit
题意:
- 给出n, a[i], b[i], t,求sum{a[i] * ln( 1+ b[i]*x) }/ (x^t)的极限{x->0}。
思路:
- 直接泰勒展开,然而考场的时候泰勒不会
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL c[20];
int main(){int n, t; cin>>n>>t;for(int i = 1; i <= n; i++){int a, b; cin>>a>>b;LL cur = a;for(int j = 1; j <= t; j++){cur *= b;if(j%2==1)c[j] += cur;else c[j] += -cur;}}if(t==0){cout<<"0\n"; return 0;}for(int i = 1; i < t; i++){if(c[i]){ cout<<"infinity\n"; return 0; }}if(c[t]==0)cout<<"0\n";else{LL d = (LL)abs(__gcd(1ll*t, c[t]));LL up = c[t]/d, dn = t/d;if(dn==1)cout<<up<<"\n";else cout<<up<<"/"<<dn<<"\n";}return 0;
}
K. Meal
题意:
- n个人,n道菜,第i个人对第j道菜好感为a[i][j]。
- n个人按序号轮流点菜,第i个人点到第j道菜的概率为a[i][j]/{S中剩余全部},把j从S中删除。
- 求第i个人点到第j道菜的概率。
思路:
- 状压dp
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1<<20;
const LL mod = 998244353;
LL pows(LL a, LL x, LL p){if(x==0)return 1; LL t = pows(a, x>>1,p);if(x%2==0)return t*t%p;return t*t%p*a%p;}
LL inv(LL x, LL p){ return pows(x,p-2,p);}int n, a[20][20], p[20][20];
int f[maxn], s[maxn];int main(){int n; cin>>n;for(int i = 0; i < n; i++)for(int j = 0; j < n; j++)cin>>a[i][j];for(int i = 0; i < (1<<n); i++){int c = __builtin_popcount(i);//有多少个位为1for(int j = 0; j < n; j++)if(!(i>>j&1))s[i] += a[c][j];s[i] = inv(s[i],mod);}f[0] = 1;for(int i = 1; i < (1<<n); i++){int c = __builtin_popcount(i)-1;for(int j = 0; j < n; j++){if(!(i>>j&1)) continue;(p[c][j] += 1ll*f[i^(1<<j)]*a[c][j]%mod*s[i^(1<<j)]%mod) %= mod;(f[i] += 1ll*f[i^(1<<j)]*a[c][j]%mod*s[i^(1<<j)]%mod) %= mod;}}for(int i = 0; i < n; i++){for(int j = 0; j < n; j++){cout<<p[i][j];if(j==n-1)cout<<"\n";else cout<<" ";}}return 0;
}
【ICPC 2021网络赛2】The 2021 ICPC Asia Regionals Online Contest (II)签到题5题相关推荐
- 2021 ICPC Asia Regionals Online Contest (II) Problem G. Limit
The 2021 ICPC Asia Regionals Online Contest (II) Problem G. Limit 在欧教的指导下,复习了下高数知识,写下了这题的题解- 做这道题之前, ...
- 2021ICPC网络赛第二场The 2021 ICPC Asia Regionals Online Contest (II) 【L Euler Function】
分析: 根据欧拉函数的那个性质 if(p是质数){if(i % p == 0) f[i * p] = f[i] * p;else f[i * p] = f[i] * (p - 1);} 每次区间乘的那 ...
- The 2022 ICPC Asia Regionals Online Contest (II) 2022ICPC第二场网络赛 ABEFGJKL题解
文章目录 A Yet Another Remainder[费马小定理] B Non-decreasing Array[线性DP] E An Interesting Sequence[签到] F Inf ...
- The 2021 ICPC Asia Regionals Online Contest (II)
比赛链接 A. Sort 暴力 k=1k=1k=1 检查数组是否有序: k=2k=2k=2 相当于再环上找个起点使得数组有序,直接判断: k≥3k\ge 3k≥3 考虑插入排序,每次暴力找到第 iii ...
- The 2022 ICPC Asia Regionals Online Contest (II) A、B、E、F、G、J、L
文章目录 A-Yet Another Remainder 题目 题解 B-Non-decreasing Array 题目 题解 E-An Interesting Sequence 题目 题解 F-In ...
- The 2022 ICPC Asia Regionals Online Contest (II) J
J:A Game about Increasing Sequences 不是特别会博弈,只能说一下大概意思 Alice and Bob like playing games. The game is ...
- The 2022 ICPC Asia Regionals Online Contest (II) B
B : Non-decreasing Array You are given a non-decreasing array of integers a1,a2,-,an. In one oper ...
- 2019 ACM - ICPC 上海网络赛 E. Counting Sequences II (指数型生成函数)
繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...
- 2016 ICPC 北京网络赛 A 恶心模拟 F 循环矩阵,FFT(待补) I 模拟
2016 ICPC 北京网络赛 A - The Book List 题意:每本书有所属种类,给出原生的存放方式,求按新的方式存放的样子. tags:坑到心态爆炸的题== 直接堆进vector里搞的, ...
最新文章
- Python 数据类型:列表
- jquery之hide()用法详解
- 第7章 面向对象编程(OOP) 《Kotin 编程思想·实战》
- php 最大数字,PHP 计算至少是其他数字两倍的最大数的实现代码
- 12-C语言排序算法
- [leetcode] Pow(x, n)
- 洛谷 P4245 【模板】MTT
- go和python组合开发_混合Python和Go
- spring整合jdbc
- JSON (一) JSON语法和数据类型
- Azure 上的网站如何识别不同国家和地区的用户
- 面试算法基础及编程 第四弹 (字符串、数值类、或其他常见相关)
- Tomcat反射时报错java.lang.ClassNotFoundException
- html如何在手机打开,HTML怎么在手机打开
- Oracle long 类型转 varchar2
- 违反计算机安全网络,违反网络安全法规定会受到哪些处罚
- 解决:启动springboot项目,Unable to start web server; nested exception is org.springframework.beans.factory
- 论文阅读 (47):DTFD-MIL: Double-Tier Feature Distillation Multiple Instance Learning for Histopathology..
- WPF UserControl响应PreviewKeyDown事件方法
- 《2023游戏行业热点趋势报告》|Party Game游戏成为新趋势,备受消费者瞩目
热门文章
- 新技能 get —— Python 断点续传下载文件
- 二叉树的遍历(先序/中序/后序,递归/迭代)与搜索
- UNIX 环境高级编程(六)—— 程序和进程
- [面试]——用一行代码判断两矩形是否相交
- matplotlib —— fill between
- 不是区块链的特征_区块链的四大特征
- linux buffer cache 过高_你真的理解Linux的内存监控吗?
- python基础代码大全-Python网络爬虫实战项目代码大全(长期更新,欢迎补充)
- python能做什么-学会Python后都能做什么?网友们的回答简直不要太厉害
- python发音模块-python 利用pyttsx3文字转语音过程详解