2018 “百度之星”程序设计大赛 - 初赛（A）

1001度度熊拼三角

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int MAXN=1e5+5;
const int INF=0x3f3f3f3f;
int a[MAXN];

int main(){
//int _;
//scanf("%d",&_);
int n;
while(~scanf("%d",&n)){
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
//a+b>c;
//b-a<c
int ans=-1;
int x,y,z;
sort(a+1,a+n+1);
for(int i=1;i<n-1;i++){
for(int j=i+1;j<n;j++){
x=a[i];
y=a[j];
int pos=upper_bound(a+j+1,a+n+1,x+y)-(a);
pos--;
if(pos>j&&x+y>a[pos]&&y-x<a[pos]&&a[pos]-x<y&&a[pos]-y<x){
ans=max(ans,x+y+a[pos]);
}
}
}
printf("%d\n",ans);
}
return 0;
}
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<list>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int MAXN=2e5+5;
const int INF=0x3f3f3f3f;
int n,q;

struct Node{
list<int> L;
list<int> rL;
}a[MAXN];

char ch = getchar();x = 0;
for (; ch < '0' || ch > '9'; ch = getchar());
for (; ch >='0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}

void init(){
for(int i=1;i<=n;i++){
a[i].L.clear();
a[i].rL.clear();
}
}

int main(){
while(~scanf("%d%d",&n,&q)){
init();
int op;
while(q--){
scanf("%d",&op);
int u,v,w,val;
list<int>::iterator it;
if(op==1){
scanf("%d%d%d",&u,&w,&val);
if(w==0){
a[u].L.push_front(val);
a[u].rL.push_back(val);
}else{
a[u].L.push_back(val);
a[u].rL.push_front(val);
}
}else if(op==2){
scanf("%d%d",&u,&w);
if(a[u].L.empty()){
printf("-1\n");
}else if(w==0){
printf("%d\n",a[u].L.front());
a[u].L.pop_front();
a[u].rL.pop_back();
}else{
printf("%d\n",a[u].L.back());
a[u].L.pop_back();
a[u].rL.pop_front();
}
}else{
scanf("%d%d%d",&u,&v,&w);
if(w==0){
it=a[u].L.end();
a[u].L.splice(it,a[v].L);
it=a[u].rL.begin();
a[u].rL.splice(it,a[v].rL);
}else{
it=a[u].L.end();
a[u].L.splice(it,a[v].rL);
it=a[u].rL.begin();
a[u].rL.splice(it,a[v].L);
}
}
//            cout<<"-----L----"<<endl;
//            for(it=a[u].L.begin();it!=a[u].L.end();it++){
//                cout<<*it<<" ";
//            }
//            cout<<endl;
//            cout<<"-----rL------"<<endl;
//            for(it=a[u].rL.begin();it!=a[u].rL.end();it++){
//                cout<<*it<<" ";
//            }
//            cout<<endl;
}
}
return 0;
}
/*
4 100
1 1 2
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<list>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int MAXN=2e3+100;
const int INF=0x3f3f3f3f;
const int MOD=998244353;
LL T[MAXN][MAXN];

LL qpow(LL x,LL y){
LL res=1;
while(y){
if(y&1) res=res*x%MOD;
x=x*x%MOD;
y>>=1;
}
return res;
}

void init(){
memset(T,0,sizeof(T));
T[0][0]=1;T[1][0]=0;T[1][1]=2;
for(int i=2;i<=1000;i++){
T[i][0]= 2*i*((2*i-1)*T[i-1][0]%MOD + (2*i-2)*T[i-2][0]%MOD)%MOD;
for(int j=1;j<=i;j++){
T[i][j] = 2*(2*i-j)*T[i-1][j-1]%MOD;
T[i][j] = (T[i][j] + ((2*i-1-j)*(2*i-2-j)%MOD+2*j)%MOD*T[i-1][j])%MOD;
T[i][j] = (T[i][j] + 2*(j+1)*(2*i-2-j)*T[i-1][j+1]%MOD)%MOD;
T[i][j] = (T[i][j] + (j+2)*(j+1)*T[i-1][j+2]%MOD)%MOD;
}
}
}

int main(){
init();
int n,d;
while(~scanf("%d%d",&n,&d)){
LL ans=0;
for(int k=0;k<=n;k++){
ans=(ans+T[n][k]*qpow(d,k)%MOD)%MOD;
}
printf("%lld\n",ans);
}
return 0;
}
/*
1 10
2 3
*/

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120