第二十五天 2021-4-8 备战CSP
刷题模块:CSP 201612-1-2
一、201609-1
如此垃圾的逻辑和代码,竟然一遍编译过,一遍AC过。
能AC的代码就是好代码。
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1010;
int n;
int num[N];
int l,r,mid;
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&num[i]);
}
sort(num,num+n);
if(n%2==0){
r=n/2;
l=r-1;
if(num[l]!=num[r]){
puts("-1");
return 0;
}
else mid=l;
}
else l=r=mid=n/2;
while(num[l]==num[mid] && num[r]==num[mid]){
l--;
r++;
if(l==0) break;
}
if(l==0 && num[l]==num[mid] && num[r]==num[mid]){
printf("%d",num[mid]);
return 0;
}
if(num[l]!=num[mid] && num[r]!=num[mid]){
printf("%d",num[mid]);
return 0;
}
puts("-1");
return 0;
}
二、201609-2
一遍过,有点爽。
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int S,T,M;
int tex[8]={0,3,10,20,25,30,35,45};
int gear[7]={35,15,30,45,260,200,250};
int domain[7]={3500,5000,8000,12500,38500,58500,83500};
int main(){
scanf("%d",&T);
int i;
M=0;
for(i=0;i<7;i++){
if(T <= M + gear[i] * (100-tex[i])) break;
M = M + gear[i] * (100-tex[i]);
}
S=domain[i-1]+((T-M)*100)/(100-tex[i]);
printf("%d\n",S);
return 0;
}
三、201609-3
一遍过,超级爽
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1010;
typedef struct Suite{
int attVal;
int heaVal;
Suite* next;
Suite():attVal(0),heaVal(0),next(nullptr){}
Suite(int attVal, int heaVal):attVal(attVal),heaVal(heaVal),next(nullptr){}
}Suite;
Suite *head[2];
int n;
int pos,att,hea,atterPos,deferPos;
int player[2];
int turn;
char summonStr[]="summon";
char attackStr[]="attack";
char endStr[]="end";
char opStr[100];
//return the pointer before pos
Suite* findSuite(int pos,int myturn){
Suite* pot=head[myturn];
while(--pos && pot->next!=nullptr){
pot=pot->next;
}
return pot;
}
//remove suite from pos
void remove(int pos,int myturn){
Suite* pot=findSuite(pos,myturn);
pot->next=pot->next->next;
}
//add a suite in pos
void summon(){
Suite* s=new Suite(att,hea);
Suite* pot=findSuite(pos,turn);
s->next=pot->next;
pot->next=s;
}
void attack(){
Suite* atter=findSuite(atterPos,turn)->next;
int anoPlayer=(turn+1)%2;
if(deferPos==0){
player[anoPlayer]-=atter->attVal;
}
else{
Suite* defer=findSuite(deferPos,anoPlayer)->next;
atter->heaVal-=defer->attVal;
defer->heaVal-=atter->attVal;
if(atter->heaVal<=0) remove(atterPos,turn);
if(defer->heaVal<=0) remove(deferPos,anoPlayer);
}
}
void init(){
head[0]=new Suite();
head[1]=new Suite();
turn=0;
player[0]=player[1]=30;
}
void output(){
//line 1
if(player[1]<=0) puts("1");
else if(player[0]<=0) puts("-1");
else puts("0");
//line 2
printf("%d\n",player[0]);
//line 3
int count=0;
Suite* temp=head[0]->next;;
while(temp!=nullptr){
count++;
temp=temp->next;
}
printf("%d ",count);
temp=head[0]->next;
while(temp!=nullptr){
printf("%d ",temp->heaVal);
temp=temp->next;
}
printf("\n");
//line 4
printf("%d\n",player[1]);
//line 5
count=0;
temp=head[1]->next;
while(temp!=nullptr){
count++;
temp=temp->next;
}
printf("%d ",count);
temp=head[1]->next;
while(temp!=nullptr){
printf("%d ",temp->heaVal);
temp=temp->next;
}
printf("\n");
}
int main()
{
init();
scanf("%d", &n);
while(n--){
scanf("%s", opStr);
if(!strcmp(opStr, summonStr)){
scanf("%d %d %d", &pos, &att, &hea);
summon();
}
else if(!strcmp(opStr, attackStr)){
scanf("%d %d", &atterPos, &deferPos);
attack();
}
else if(!strcmp(opStr, endStr)){
turn=(turn+1)%2;
}
else{
printf("Error\n");
}
}
output();
return 0;
}

1096

被折叠的 条评论
为什么被折叠?



