Welcome to yjjr's blog!
阿新 • • 發佈:2018-12-16
T1 yyy點餐
題意
給出長度為的序列,求有所有不同的組合的代價總和(每種組合的代價為該組合內所有數之和)
對於全部資料,有
題解
一眼就能秒掉的水題
求組合數的話,就用乘法逆元即可
code
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define mem(x,num) memset(x,num,sizeof x)
#define ll long long
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
ll f=1,x=0;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;
}
//******head by yjjr******
const ll mod=998244353;
int n;
ll sum1=1,sum2=0;
ll inv(ll a){return a==1?1:(ll)(mod-mod/a)*inv(mod%a)%mod;}
void C(ll n,ll m){
if(m<0||n<m)return;//if(m>n-m)m=n-m;
ll up=1,down=1;
rep(i,0,m-1){up=up*(n-i)%mod;down=down*(i+1)%mod;sum1+=up*inv(down)%mod;sum1%=mod;}
}
int main(){
freopen("T1.in","r",stdin);
freopen("T1.out","w",stdout);
n=read();
C(n-1,n-1);//puts("R");
rep(i,1,n)sum2+=read(),sum2%=mod;
//cout<<sum1<<' '<<sum2<<endl;
cout<<1ll*sum1*sum2%mod<<endl;
return 0;
}
T2 yyy送禮物
題意
求
對於全部資料,有
題解
毒瘤數論題
先是找規律手玩了2h,最後對拍發現規律找錯了GG
然後推式子
然後可以用線性篩求約數和
code
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
ll f=1,x=0;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;
}
//**********head by yjjr**********
const int maxn=1e7+6;
bool not_prime[maxn+6];
int prime[maxn],cnt=0;
ll sd[maxn+6],sp[maxn+6],pre[maxn+6];
void Pre(){
not_prime[1]=1;sd[1]=sp[1]=1;
rep(i,2,maxn){
if(!not_prime[i]){
prime[++cnt]=i;
sd[i]=sp[i]=i+1;
}
rep(j,1,cnt){
if(i*prime[j]>maxn)break;
not_prime[i*prime[j]]=1;
if(i%prime[j]==0){
sd[i*prime[j]]=sd[i]/sp[i]*(sp[i]*prime[j]+1);
sp[i*prime[j]]=sp[i]*prime[j]+1;
break;
}else{
sd[i*prime[j]]=sd[i]*sd[prime[j]];
sp[i*prime[j]]=prime[j]+1;
}
}
}
rep(i,1,maxn)pre[i]=pre[i-1]+sd[i];
}
int main()
{
freopen("T2.in","r",stdin);
freopen("T2.out","w",stdout);
Pre();
int T=read();
while(T--){
ll x=read();
printf("%lld\n",x*x-pre[x]);
}
return 0;
}
T3 yyy的迷失
題意
給出大小為的正方形,其中有一些帶方向的箭頭(平行於x軸或y軸),從一個點出發(給定方向),如果遇到箭頭,就會沿著箭頭走,問最後停留在什麼位置
對於全部資料,保證:
(偽)題解
一看就是資料結構題,再看下std的程式碼長度,,開始棄療
然後放上50pts的暴力程式碼
code
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
ll f=1,x=0;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;
}
//**********head by yjjr**********
const int maxn=3e3+6;
int Map[maxn][maxn]={0},x1,x2,y1,y2,k,n,m,T;
char ch;
void check(){
if(x1==x2){
if(y1<y2)rep(i,y1,y2)Map[x1][i]=1;
else rep(i,y2,y1)Map[x1][i]=2;
}
else if(y1==y2){
if(x1>x2)rep(i,x2,x1)Map[i][y1]=3;
else rep(i,x1,x2)Map[i][y1]=4;
}
}
int main()
{
freopen("T3.in","r",stdin);
freopen("T3.out","w",stdout);
n=read(),m=read();
rep(i,1,n){
x1=read(),y1=read(),x2=read(),y2=read();
check();
}
T=read();
while(T--){
int x=read(),y=read();
cin>>ch;getchar();int t=read();
if(ch=='U')k=1;
if(ch=='D')k=2;
if(ch=='L')k=3;
if(ch=='R')k=4;
// cout<<k<<"R\n";
rep(j,1,t){
if(Map[x][y]!=0)k=Map[x][y];
if(k==1)y++;
if(k==2)y--;
if(k==3)x--;
if(k==4)x++;
if(x>m){x--;break;}
else if(x<0){x++;break;}
else if(y>m){y--;break;}
else if(y<0){y++;break;}
}
printf("%d %d\n",x,y);
}
return 0;
}