The 15th Chinese Northeast Collegiate Programming Contest
linkkkkkk
1001 Matrix
题意:
用 [ 1 , n 2 ] [1,n^2] [1,n2]的数填 n ∗ n n*n n∗n的矩阵,每个数字只能用一次,记 a i a_i ai表示第 i i i行的最大值
S = a 1 , a 2 , . . . , a n ∩ 1 , 2 , . . . , n . S={a1,a2,...,an}∩{1,2,...,n}. S=a1,a2,...,an∩1,2,...,n..
求 ∑ ∣ S ∣ \sum|S| ∑∣S∣
思路:
考虑每一个数的贡献,比如 1 1 1可以作为贡献的方案数就是 n ∗ C n 2 − 1 n − 1 n*C_{n^2-1}^{n-1} n∗Cn2−1n−1。
其中组合数部分表示 1 1 1作为该行的最小值出现,选择剩下的数的方案数; n n n表示该行可以出现在 1 − n 1-n 1−n里任意一行。
最后还要乘 n ! ∗ ( n 2 − n ) ! n!*(n^2-n)! n!∗(n2−n)!。前者表示 1 1 1所在行的所有数都可以全排列一遍,后者表示剩下的数可以全排列,对 1 1 1的贡献是不影响的。
累加出 1 − n 1-n 1−n的贡献,直接求或打表 O ( 1 ) O(1) O(1)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn = 2e7 + 5e6 + 7;
const int mod = 998244353;ll qpow(ll a, ll b,ll p)
{ll ans = 1;while(b){if(b & 1) ans = ans * a % p;a = a * a % p;b >>= 1;}return ans;
}ll fac[maxn];
void init()
{fac[0] = 1;for(int i = 1; i < maxn; i++){fac[i] = fac[i - 1] * i % mod;}
}
ll infac(ll x)
{return qpow(x, mod - 2, mod);
}
ll C(ll n, ll m)
{if(n < m) return 0;return fac[n] * infac(fac[m]) % mod * infac(fac[n - m]) % mod;
}
void solve()
{ll n;scanf("%lld",&n);ll ans=n*fac[n]%mod*fac[n*n-n]%mod;ll sum=0;for(int i=1;i<=n;i++){sum+=C(n*n-i,n-1);sum=sum%mod;}printf("%lld\n",ans*sum%mod);
}int main()
{init();int t = 1;scanf("%d", &t);while(t--){solve();}return 0;
}
1003 Vertex Deletion
linkkkk
1004 Lowbit
题意:
两种操作:
1. 1. 1.给区间 [ l , r ] [l,r] [l,r]的所有数都加 l o w b i t ( a i ) lowbit(a_i) lowbit(ai)
2. 2. 2.区间求和
思路:
如果一个区间的数都变成 10000 10000 10000(二进制)这种形式,操作 1 1 1就相当于区间乘法,维护懒标就好了。设一个标记 f l a g flag flag表示该段区间都是 1000 1000 1000这种形式,对于操作 1 1 1的区间,看是否能转化成区间乘法
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PLL;
typedef pair<int, int>PII;
typedef pair<double, double>PDD;
#define I_int ll
inline ll read(){ll x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;}inline void write(ll x){if (x < 0) x = ~x + 1, putchar('-');if (x > 9) write(x / 10);putchar(x % 10 + '0');}#define read read()
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
const double PI=acos(-1.0);
ll ksm(ll a,ll b,ll p){ll res=1;a%=p;while(b){//&运算当相应位上的数都是1时,该位取1,否则该为0。if(b&1)res=1ll*res*a%p;//转换为ll型a=1ll*a*a%p;b>>=1;//十进制下每除10整数位就退一位 }return res;
}const int maxn=1e5+100;
const ll mod=998244353;
struct node{int l,r,flag;ll sum,laz;
}tr[maxn*4];
int n,m;
ll a[maxn];ll lowbit(ll x){return x&-x;}void pushup(int u){tr[u].sum=(tr[u<<1].sum+tr[u<<1|1].sum)%mod;tr[u].flag=tr[u<<1].flag&tr[u<<1|1].flag;
}void pushdown(int u){if(tr[u].laz){ll t=tr[u].laz;tr[u<<1].sum=(tr[u<<1].sum*ksm(2,t,mod))%mod;tr[u<<1|1].sum=(tr[u<<1|1].sum*ksm(2,t,mod))%mod;tr[u<<1].laz+=t;tr[u<<1|1].laz+=t;tr[u].laz=0;}
}void build(int u,int l,int r){tr[u].l=l,tr[u].r=r;tr[u].flag=tr[u].laz=tr[u].sum=0;if(l==r){tr[u].flag=tr[u].laz=0;tr[u].sum=a[l];if(a[l]==lowbit(a[l])) tr[u].flag=1;return ;}int mid=(l+r)/2;build(u<<1,l,mid);build(u<<1|1,mid+1,r);pushup(u);
}void update(int u,int l,int r,int ql,int qr){if(tr[u].flag&&l>=ql&&r<=qr){tr[u].laz++;tr[u].sum=(tr[u].sum*2)%mod;return ;}if(l==r){ll tmp=lowbit(a[l]);a[l]+=tmp;tr[u].sum+=tmp;if(tr[u].sum==lowbit(tr[u].sum)){tr[u].flag=1;}return ;}pushdown(u);int mid=(l+r)/2;if(ql<=mid) update(u<<1,l,mid,ql,qr);if(qr>mid) update(u<<1|1,mid+1,r,ql,qr);tr[u].sum=(tr[u<<1].sum+tr[u<<1|1].sum)%mod;tr[u].flag=tr[u<<1].flag&tr[u<<1|1].flag;
}ll query(int u,int l,int r,int ql,int qr){if(l>=ql&&r<=qr){return tr[u].sum;}pushdown(u);ll ans=0;int mid=(l+r)/2;if(ql<=mid) ans=(ans+query(u<<1,l,mid,ql,qr))%mod;if(qr>mid) ans=(ans+query(u<<1|1,mid+1,r,ql,qr))%mod;return ans;
}int main(){int _;cin>>_;while(_--){n=read;rep(i,1,n) a[i]=read;build(1,1,n);m=read;while(m--){int op=read,l=read,r=read;if(op==1) update(1,1,n,l,r);else printf("%lld\n",query(1,1,n,l,r));}}return 0;
}
1005 Easy Math Problem
思维构造
int main()
{int t=1;scanf("%d",&t);while(t--){ll n;scanf("%lld",&n);cout<<6*n<<" "<<3<<endl;cout<<n<<" "<<2*n<<" "<<3*n<<endl;}return 0;
}
1009 Takeaway
阅读理解题
int a[]={0,7,27,41,49,63,78,108};
int main(){closeSync;int _=read;while(_--){int n=read,sum=0;rep(i,1,n){int x=read;sum+=a[x];}int ans=0;if(sum>=120) ans+=50;if(sum<120&&sum>=89) ans+=30;if(sum<89&&sum>=69) ans+=15;cout<<sum-ans<<endl;}return 0;
}
1010 Transform
题意:
三维空间里给出一个点和一个向量,问点围绕向量旋转 t t t度后,输出 z z z坐标大的点
思路:
板子题
代码:
const double PI=acos(-1.0);
//定义返回结构体struct Point3f{Point3f(double _x, double _y, double _z){x = _x;y = _y;z = _z;}double x;double y;double z;};Point3f cul(double old_x, double old_y, double old_z, double vx, double vy, double vz, double theta){double r = theta * PI / 180;double c = cos(r);double s = sin(r);double new_x = (vx*vx*(1 - c) + c) * old_x + (vx*vy*(1 - c) - vz*s) * old_y + (vx*vz*(1 - c) + vy*s) * old_z;double new_y = (vy*vx*(1 - c) + vz*s) * old_x + (vy*vy*(1 - c) + c) * old_y + (vy*vz*(1 - c) - vx*s) * old_z;double new_z = (vx*vz*(1 - c) - vy*s) * old_x + (vy*vz*(1 - c) + vx*s) * old_y + (vz*vz*(1 - c) + c) * old_z;return Point3f(new_x, new_y, new_z);}int main(){int _=read;while(_--){double x1,y1,z1,x2,y2,z2,t;cin>>x1>>y1>>z1>>x2>>y2>>z2>>t;double sum=sqrt(x1*x1+y1*y1+z1*z1);x1/=sum,y1/=sum,z1/=sum;Point3f t1=cul(x2,y2,z2,x1,y1,z1,t);Point3f t2=cul(x2,y2,z2,x1,y1,z1,-1*t);if(t1.z>t2.z) printf("%.6f %.6f %.6f\n",t1.x,t1.y,t1.z);else printf("%.6f %.6f %.6f\n",t2.x,t2.y,t2.z);}return 0;
}
1011 City
题意:
给出一个图,每次询问给出 x x x,每次将边权 < x <x <x的边摧毁,问还能互相到达的点的对数。
思路:
按照边权从大到小排序,依次连边,每次连边产生的贡献是 s i z [ u ] ∗ s i z [ v ] siz[u]*siz[v] siz[u]∗siz[v]
代码:
const int maxn=2e5+10,inf=0x3f3f3f3f;
const double eps=1e-5;int n,m,q;
struct node{int u,v,w;
}edge[maxn];bool cmp(node a,node b){return a.w>b.w;
}struct ask{int id,w;
}qask[maxn];bool cmp1(ask a,ask b){return a.w>b.w;
}ll root[maxn],siz[maxn],ans[maxn];int Find(int x){if(x!=root[x]) root[x]=Find(root[x]);return root[x];
}int main(){closeSync;int _;cin>>_;while(_--){cin>>n>>m>>q;rep(i,1,m){cin>>edge[i].u>>edge[i].v>>edge[i].w;}sort(edge+1,edge+1+m,cmp);rep(i,1,n) root[i]=i,siz[i]=1;rep(i,1,q){cin>>qask[i].w;qask[i].id=i;}sort(qask+1,qask+1+q,cmp1);ll now=1,sum=0;for(int i=1;i<=q;i++){while(edge[now].w>=qask[i].w){int u=edge[now].u,v=edge[now].v;int fu=Find(u),fv=Find(v);if(fu!=fv){sum+=siz[fu]*siz[fv];root[fu]=fv;siz[fv]+=siz[fu];}now++;}ans[qask[i].id]=sum;}rep(i,1,q) cout<<ans[i]<<endl;}return 0;
}
1013 Master of Shuangpin
思路:
模拟。
代码:
const int maxn=500005,inf=0x3f3f3f3f;
const double eps=1e-5;
map<string,string>mp;
void init(){mp["q"] = "q";mp["iu"] = "q";mp["w"] = "w";mp["ei"] = "w";mp["e"] = "e";mp["r"] = "r";mp["uan"] = "r";mp["t"] = "t";mp["ue"] ="t";mp["y"] = "y";mp["un"] = "y";//mp["u"] = "u";mp["sh"] = "u";mp["i"] = "i";mp["ch"] = "i";mp["o"] = "o";mp["uo"] = "o";mp["p"] = "p";mp["ie"] = "p";mp["a"] ="a";mp["s"] = "s";mp["ong"] = "s";mp["iong"] = "s";mp["d"] = "d";mp["ai"] = "d";mp["f"] = "f";mp["en"] = "f";mp["g"] = "g";mp["eng"] = "g";mp["h"] = "h";mp["ang"] = "h";mp["j"] = "j";mp["an"] = "j";mp["k"] = "k";mp["uai"] = "k";mp["ing"] = "k";mp["l"] = "l";mp["uang"] = "l";mp["iang"] = "l";mp["z"] = "z";mp["ou"] = "z";mp["x"] = "x";mp["ia"] = "x";mp["ua"] = "x";mp["c"] = "c";mp["ao"] = "c";mp["v"] = "v";mp["ui"] = "v";mp["zh"] = "v";mp["b"] = "b";mp["in"] = "b";mp["n"] = "n";mp["iao"] = "n";mp["m"] = "m";mp["ian"] = "m";}int main(){init();string s;while(getline(cin,s)){stringstream ss;ss<<s;string tt="";while(ss>>s){if(s.size()==1) tt=tt+s+s+" ";//cout<<s<<s<<" ";else if(s.size()==2) tt=tt+s+" ";//cout<<s<<" ";else{if(mp.count(s)){tt=tt+s[0]+mp[s]+" ";
// cout<<s[0]<<mp[s]<<" ";continue;}string res="";bool flag=0;for(int i=1;i<s.size();i++){string s1=s.substr(0,i);string s2=s.substr(i,s.size()-1);//cout<<s1<<" "<<s2<<endl;if(mp.count(s1)&&mp.count(s2)){flag=1;res=mp[s1]+mp[s2];break;}}tt=tt+res+" ";
// cout<<res<<" ";}}tt=tt.substr(0,tt.size()-1);cout<<tt<<endl;}return 0;
}
The 15th Chinese Northeast Collegiate Programming Contest相关推荐
- The 15th Chinese Northeast Collegiate Programming Contest部分题解
The 15th Chinese Northeast Collegiate Programming Contest 目录 E. Easy Math Problem 题目思路 题目代码 I. Takea ...
- The 15th Chinese Northeast Collegiate Programming Contest D题
题目链接 大致题意: 给你一段含n个数字的序列,对于这段序列可以有m次操作. 操作有两种类型: 1.(1,L,R)表示将(L,R)区间的每个数加自身的lowbit值(若一个数为x,则其lowbit值为 ...
- 【21.10.24】The 15th Chinese Northeast Collegiate Programming Contest题解
A. Matrix(组合数+数学) #include <bits/stdc++.h> using namespace std; #define mod 998244353 ll fac[1 ...
- The 15th Chinese Northeast Collegiate Programming Contest K.City
目录 题目: 思路: 代码: 题目: 原题: Lucida occupies n cities connected by m undirected roads, and each roa ...
- The 15th Chinese Northeast Collegiate Programming Contest - K.City
虽然不难,但是感觉很有意思的一道题,下面有几个点感觉还是挺妙的: · 并查集只能加边不能减边: ·对数据进行离线处理,方便我们进行排序处理(后面会解释): 首先数据的范围很大,如果我们每做一次判断都要 ...
- The 15th Chinese Northeast Collegiate Programming Contest. A Matrix
题意: $$用[1,2,...,n^2]填n\times n的矩阵,每个数字只能用一次,记:a_i为第i行的最小值:$$ $$S=a_1,a_2,...,a_n\cap{1,2,...,n};$$ $ ...
- The 15th Chinese Northeast Collegiate Programming Contest 题解(CCPC压力测试?
CCPC压力测试用了这套题,和一个队友一起搞了.初期签到还算比较顺利,还碰到了挺多有意思的题目,做的好爽,但还是犯了很多低级错误,对于杭电要时时刻刻关同步或者scanf,并且写代码还是要仔细些. A. ...
- 【The 13th Chinese Northeast Collegiate Programming Contest】I. Temperature Survey
题目描述 [题目链接](https://codeforces.com/gym/102220/problem/I) 给定长度为 $n$ 的 $a$ 序列,保证 $a_n \le n$,求有多少个长度为 ...
- The 14th Chinese Northeast Collegiate Programming Contest 补题
题目链接 https://codeforces.com/gym/102801 参考题解 B - Team 简要题意: 给定 nnn 和 MMM,有三个组 ABCABCABC,每组 nnn 个人,每人都 ...
最新文章
- 属性为nil的时候测试是否crash nil是不会崩溃的
- 推荐系统的作用和问题
- C语言中变量的链接属性
- C# 系统应用之获取Windows最近使用记录
- 611. 有效三角形的个数
- (转载)最黑的黑客米特尼克:多次耍FBI 终被高手擒
- iPhone 11系列低至4599元,40亿消费券开抢!618正式开启了
- css 动画类库Animate.css
- 简单的Python少儿编程
- Error:algorithms should be set错误
- c语言中judge的用法,judge的用法
- 事务的四大属性ACID即事务的原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)、持久性(Durability.。...
- maven通过mvn命令添加oracle依赖
- uniapp PDA广播扫码
- 学习python 第二十六天
- 牛客小白月赛3 C.博弈
- 人生的两个方向:一个是出门,一个是回家(转载)
- Mediacodec 如何硬件解码到纹理的
- carbon安装win7 thinkpad x1_联想ThinkPad New X1 Carbon安装win7系统教程
- HTML+CSS抗疫期末大作业:抗疫网站设计——新冠抗疫(4页) 学生DW网页设计作业成品 web课程设计网页规划与设计...