团体程序设计天梯赛2020游记
赛前
上午和wjy一块听了讲座,没听完就溜了,武汉又下雨了。。。
想起来自己没拿身份证,赶快去拿,然后走到学院门口已经11点多了
组装好设备(拍照没有自动对焦简直太蠢了,身份证永远拍不清楚)
组装完告诉我不能动手机电脑,所以我直接被强行戒网了
然后发现自己没拿电脑充电器,赶快走回去拿
有惊无险的开始了
比赛
题目没啥意思(除了最后一个,还没想出来)
3-1老是WA一个,完全想不出来
其他的就全是手速和模拟(话说题意好不清晰)
贴个代码吧
A
#include <cstdio>
int main(){
printf("Talk is cheap. Show me the code.");
return 0;
}
B
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
printf("%lld",1LL*a*b*c);
return 0;
}
C
#include <cstdio>
#include <algorithm>
using namespace std;
double a,c;
int x;
int main(){
scanf("%lf %d %lf",&a,&x,&c);
if(x){//1.26
printf("%.2lf ",a*1.26);
if(c<a*1.26){
printf("T_T\n");
}
else{
printf("^_^\n");
}
}
else{//1.26
printf("%.2lf ",a*2.455);
if(c<a*2.455){
printf("T_T\n");
}
else{
printf("^_^\n");
}
}
}
D
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
double sum,x;
int n;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lf",&x);
sum+=1.0/x;
}
sum=sum/n;
printf("%.2lf\n",1.0/sum);
return 0;
}
E
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int t[5],k,low,cnt=0,hi,ans;
int mabs(int x){
if(x>=0)
return x;
else
return -x;
}
int main(){
scanf("%d %d %d %d %d %d",&t[1],&t[2],&t[3],&t[4],&low,&k);
hi=max(max(max(t[1],t[2]),t[3]),t[4]);
for(int i=1;i<=4;i++){
if(mabs(t[i]-hi)>k||t[i]<low){
cnt++;
ans=i;
}
}
if(cnt==0)
printf("Normal\n");
else if(cnt==1){
printf("Warning: please check #%d!\n",ans);
}
else{
printf("Warning: please check all the tires!\n");
}
return 0;
}
F
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> ans;
int main(){
string s="chi1 huo3 guo1";
string t;
int cnt=0;
while(getline(cin,t)){
if(t==".")
break;
++cnt;
if(t.find(s)<t.length()){
// cout<<"!"<<t.find(s);
ans.push_back(cnt);
}
}
printf("%d\n",cnt);
if(ans.size()!=0)
printf("%d %d\n",ans[0],ans.size());
else
printf("-_-#\n");
return 0;
}
G
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int pow2[31];
int n,m;
int work(){
int t=1;
for(int i=1;i<=n;i++){
char c=getchar();
while(c!='y'&&c!='n')
c=getchar();
if(c=='y')
t=t*2;
else
t=t*2+1;
}
return t-(pow2[n]-1);
}
int main(){
pow2[0]=1;
for(int i=1;i<=30;i++)
pow2[i]=pow2[i-1]*2;
scanf("%d %d",&n,&m);
for(int i=1;i<=m;i++)
printf("%d\n",work());
return 0;
}
H
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
bool vis[10]={0};
int num[4][4],seex,seey;
int score[30]={0};
int main(){
score[6]=10000;
score[7]=36;
score[8]=720;
score[9]=360;
score[10]=80;
score[11]=252;
score[12]=108;
score[13]=72;
score[14]=54;
score[15]=180;
score[16]=72;
score[17]=180;
score[18]=119;
score[19]=36;
score[20]=306;
score[21]=1080;
score[22]=144;
score[23]=1800;
score[24]=3600;
for(int i=1;i<=3;i++)
for(int j=1;j<=3;j++){
scanf("%d",&num[i][j]);
vis[num[i][j]]=1;
if(num[i][j]==0){
seex=i;
seey=j;
}
}
for(int i=1;i<=9;i++)
if(!vis[i]){
num[seex][seey]=i;
break;
}
for(int i=1;i<=3;i++){
int x,y;
scanf("%d %d",&x,&y);
printf("%d\n",num[x][y]);
}
int opt;
scanf("%d",&opt);
switch(opt){
case 1:{
printf("%d\n",score[num[1][1]+num[1][2]+num[1][3]]);
break;
}
case 2:{
printf("%d\n",score[num[2][1]+num[2][2]+num[2][3]]);
break;
}
case 3:{
printf("%d\n",score[num[3][1]+num[3][2]+num[3][3]]);
break;
}
case 4:{
printf("%d\n",score[num[1][1]+num[2][1]+num[3][1]]);
break;
}
case 5:{
printf("%d\n",score[num[1][2]+num[2][2]+num[3][2]]);
break;
}
case 6:{
printf("%d\n",score[num[1][3]+num[2][3]+num[3][3]]);
break;
}
case 7:{
printf("%d\n",score[num[1][1]+num[2][2]+num[3][3]]);
break;
}
case 8:{
printf("%d\n",score[num[1][3]+num[2][2]+num[3][1]]);
break;
}
}
return 0;
}
I
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>
using namespace std;
stack<int> S1,S2;
int op,n2,n1,n;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&n1);
S1.push(n1);
}
for(int i=1;i<n;i++){
char c=getchar();
while(c!='+'&&c!='-'&&c!='*'&&c!='/')
c=getchar();
if(c=='+')
S2.push(1);
else if(c=='-')
S2.push(2);
else if(c=='*')
S2.push(3);
else if(c=='/')
S2.push(4);
}
while(S1.size()&&S2.size()){
n1=S1.top();
S1.pop();
n2=S1.top();
S1.pop();
op=S2.top();
S2.pop();
if(op==1){//+
S1.push(n2+n1);
}
else if(op==2){//-
S1.push(n2-n1);
}
else if(op==3){//*
S1.push(n2*n1);
}
else if(op==4){
if(n1==0){
printf("ERROR: %d/0\n",n2);
return 0;
}
S1.push(n2/n1);
}
}
printf("%d\n",S1.top());
S1.pop();
return 0;
}
J
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
struct Quest{
string name,ID_Card,tim;
int status,id;
}X;
int D,P,ti,si;
map<string,int> date;
set<string> vis;
vector<Quest> Quests,Out;
bool cmp(Quest a,Quest b){
return (a.tim<b.tim)||((a.tim==b.tim)&&(a.id<b.id));
}
bool check(string tmp){
for(int i=0;i<tmp.length();i++)
if(!(tmp[i]>='0'&&tmp[i]<='9'))
return false;
return true;
}
void work(int day){
cin>>ti>>si;
Quests.clear();
for(int i=1;i<=ti;i++){
cin>>X.name>>X.ID_Card>>X.status>>X.tim;
X.id=i;
Quests.push_back(X);
if(X.status==1&&X.ID_Card.length()==18&&check(X.ID_Card)){
Out.push_back(X);
}
}
sort(Quests.begin(),Quests.end(),cmp);
//for(int i=0;i<Quests.size();i++){
// cout<<Quests[i].name<<" "<<Quests[i].ID_Card<<" "<<Quests[i].status<<" "<<Quests[i].tim<<endl;
//}
for(int i=0;i<Quests.size();i++){
if(si<=0)
break;
if(Quests[i].ID_Card.length()!=18)
continue;
if(!check(Quests[i].ID_Card))
continue;
if((!date.count(Quests[i].ID_Card))||(date.count(Quests[i].ID_Card)&&day-P>date[Quests[i].ID_Card])){
cout<<Quests[i].name<<" "<<Quests[i].ID_Card<<endl;
si--;
//vis.insert(Quests[i].ID_Card);
date[Quests[i].ID_Card]=day;
}
}
}
int main(){
cin>>D>>P;
for(int i=1;i<=D;i++)
work(i);
for(int i=0;i<Out.size();i++){
if(vis.count(Out[i].ID_Card))
continue;
vis.insert(Out[i].ID_Card);
cout<<Out[i].name<<" "<<Out[i].ID_Card<<endl;
}
return 0;
}
K
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n,dfs_id=0,need;
int d=1;
int id[100],w[100],pow2[100];
void get_id(int dep,int tmp){
if(dep==d&&need==0)
return;
if(dep==d&&need!=0){
need--;
dfs_id++;
id[tmp]=dfs_id;
return;
}
get_id(dep+1,tmp*2);//L
get_id(dep+1,tmp*2+1);
++dfs_id;
id[tmp]=dfs_id;
return;
}
int main(){
pow2[0]=1;
for(int i=1;i<=30;i++)
pow2[i]=pow2[i-1]*2;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&w[i]);
while(n>pow2[d]-1)
d++;
need=n-(pow2[d-1]-1);
get_id(1,1);
for(int i=1;i<n;i++)
printf("%d ",w[id[i]]);
printf("%d",w[id[n]]);
return 0;
}
L
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n,m,dis[300][300],vis[300],N,path[300],ansid,K,ansnum=0;
long long ans=0x3f3f3f3f3f;
void check(int id){
for(int i=1;i<=n;i++){
vis[i]=false;
}
long long tmp=0;
int last=0;
for(int i=1;i<=N;i++){
if(vis[path[i]])
return;
vis[path[i]]=true;
tmp+=dis[last][path[i]];
last=path[i];
}
tmp+=dis[last][0];
for(int i=1;i<=n;i++)
if(!vis[i])
return;
if(tmp>0x3f3f3f3f)
return;
ansnum++;
if(tmp>ans)
return;
else if(tmp==ans){
}
else{
ansid=id;
ans=tmp;
}
}
int main(){
memset(dis,0x3f,sizeof(dis));
scanf("%d %d",&n,&m);
for(int i=1;i<=m;i++){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
dis[a][b]=c;
dis[b][a]=c;
}
scanf("%d",&K);
for(int i=1;i<=K;i++){
scanf("%d",&N);
for(int j=1;j<=N;j++)
scanf("%d",&path[j]);
check(i);
}
printf("%d\n%d %d\n",ansnum,ansid,ans);
return 0;
}
M
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
int n,m,A,B;
namespace normal{
int u[150000],v[150000],fir[1000],nxt[150000],cnt,num[1000],in[1000],vis[1000];
void addedge(int ui,int vi){
++cnt;
u[cnt]=ui;
v[cnt]=vi;
in[vi]++;
nxt[cnt]=fir[ui];
fir[ui]=cnt;
}
void bfs(int s){
queue<int> q;
num[s]=1;
q.push(s);
while(!q.empty()){
int x=q.front();
q.pop();
for(int i=fir[x];i;i=nxt[i]){
in[v[i]]--;
num[v[i]]+=num[x];
if(!in[v[i]]){
q.push(v[i]);
}
}
}
}
void bfs2(int s){
queue<int> q;
q.push(s);
while(!q.empty()){
int x=q.front();
q.pop();
// printf("!x=%d\n",x);
if(vis[x])
continue;
vis[x]=true;
for(int i=fir[x];i;i=nxt[i]){
q.push(v[i]);
}
}
}
int work(void){
memset(num,0,sizeof(num));
bfs(A);
bfs2(A);
return num[B];
}
};
namespace rev{
int u[150000],v[150000],fir[1000],nxt[150000],cnt,vis[1000]={0};
void addedge(int ui,int vi){
// printf("u=%d v=%d\n",ui,vi);
++cnt;
u[cnt]=ui;
v[cnt]=vi;
nxt[cnt]=fir[ui];
fir[ui]=cnt;
}
void bfs(int s){
queue<int> q;
q.push(s);
while(!q.empty()){
int x=q.front();
q.pop();
// printf("!x=%d\n",x);
if(vis[x])
continue;
vis[x]=true;
for(int i=fir[x];i;i=nxt[i]){
q.push(v[i]);
}
}
}
void work(void){
memset(vis,0,sizeof(vis));
bfs(B);
}
};
bool work(){
for(int i=1;i<=n;i++)
if(normal::vis[i]&&(!rev::vis[i]))
return false;
return true;
}
int main(){
scanf("%d %d",&n,&m);
for(int i=1;i<=m;i++){
int a,b;
scanf("%d %d",&a,&b);
normal::addedge(a,b);
rev::addedge(b,a);
}
scanf("%d %d",&A,&B);
printf("%d ",normal::work());
rev::work();
if(work()){
printf("Yes\n");
}
else{
printf("No\n");
}
return 0;
}
N
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define int long long
int sum[100100<<2];
void pushup(int o){
sum[o]=sum[o<<1]+sum[o<<1|1];
}
void build(int l,int r,int t){
if(l==r){
sum[t]=l*l;
return;
}
int mid=(l+r)>>1;
build(l,mid,t<<1);
build(mid+1,r,t<<1|1);
pushup(t);
}
void modi(int l,int r,int pos,int val,int t){
if(l==r){
sum[t]=l*val;
return;
}
int mid=(l+r)>>1;
modi(l,mid,pos,val,t<<1);
modi(mid+1,r,pos,val,t<<1|1);
pushup(t);
}
int n,q;
signed main(){
scanf("%lld %lld",&n,&q);
build(1,n,1);
for(int i=1;i<=q;i++){
int x,y;
char op=getchar();
while(op!='+'&&op!='-')
op=getchar();
scanf("%lld %lld",&op,&x,&y);
if(op=='+'){
modi(1,n,x,y,1);
modi(1,n,y,x,1);
printf("%lld\n",sum[1]);
}
else{
modi(1,n,x,x,1);
modi(1,n,y,y,1);
printf("%lld\n",sum[1]);
}
}
return 0;
}
结语
结果貌似不错?搞到了一个湖北Rk1。暴力是好文明