我也写个题解喽
wwww为了被显示在题解区就投 M 题题解了wwww
language : C++
代码中头文件均省略。
A. A Greeting from ACM/ICPC Lab
阅读理解题,注意「输出描述」里有四个字符的提示,输出 deer 即可。
B. A very easy problem
直接模拟即可,注意特判 0。
Code:
using namespace std;
string str;
int main()
{
cin>>str; int l=str.length();
for (int i=0;i<l;i++)
{
if ((i!=l-1)&&(str[i+1]=='0')) cout<<char((str[i]-'0')*10+'`'),++i;
else cout<<char(str[i]-'1'+'a');
} // putchar 会玄学 WA
return 0;
} C. 送信
暴力模拟即可。
Code:
using namespace std;
string str;
int x,y;
int main()
{
cin>>str; int l=str.length();
for (int i=0;i<l;i++)
{
if (str[i]=='E') ++x;
else if (str[i]=='S') --y;
else if (str[i]=='W') --x;
else ++y;
} printf("%d %d",x,y);
return 0;
} F. WHQ的考试成绩
排个序即可,注意第 大要反向。
Code:
using namespace std;
const int N=1005;
int a[N],n,k;
int main()
{
scanf("%d%d",&n,&k);
for (int i=0;i<n;i++) scanf("%d",a+i);
sort(a,a+n); printf("%d",a[n-k]);
return 0;
} H. 方格染色
画几个图,大胆猜想答案就是 的最小非平凡因子,然后 A 了
(没错,我就是这么 A 的qwq)
Code:
using namespace std;
int n,m,k;
int main()
{
scanf("%d%d",&n,&m);
for (int k=2;k*k<=n*m;k++)
if (n*m%k==0){printf("%d",k); return 0;}
return 0;
} I. 纪念币
枚举买入卖出点即可。
Code:
using namespace std;
const int N=1005;
int a[N],n,ans;
int main()
{
scanf("%d",&n);
for (int i=0;i<n;i++) scanf("%d",a+i);
for (int i=0;i<n;i++)
for (int j=i;j<n;j++)
ans=max(ans,a[j]-a[i]);
printf("%d",ans);
return 0;
} J. 开火车
暴力模拟即可。
Code:
//#define DEBUG
#ifdef ONLINE_JUDGE
#undef DEBUG
#endif
using namespace std;
const int N=105,CARD_COUNT=52;
int card[N],box[N],top=0;
struct player
{
int cd[N],tp;
player(){tp=0;}
inline void push(int x){cd[tp]=x; ++tp;}
inline void repush(int x)
{
for (int i=tp-1;i>=0;i--) cd[i+1]=cd[i];
cd[0]=x; ++tp;
}
inline void pop()
{
--tp; int now=cd[tp];
for (int i=0;i<top;i++)
if (box[i]==now)
{
for (int j=i;j<top;j++) this->repush(box[j]);
this->repush(now); top=i; return ;
} box[top]=now; ++top;
}
inline bool empty(){return !tp;}
inline int size(){return tp;}
void output() // debug
{
printf("! ");
for (int i=0;i<tp;i++) printf("%d ",cd[i]);
puts("");
}
}zcl,ajh;
void output() // debug
{
printf("! ");
for (int i=0;i<top;i++) printf("%d ",box[i]);
puts("");
}
int main()
{
for (int i=1;i<=CARD_COUNT;i++) scanf("%d",card+i);
for (int i=CARD_COUNT;i>=1;i--)
{
if (i&1) zcl.push(card[i]);
else ajh.push(card[i]);
}
#ifdef DEBUG
puts(" INIT : ");
cout<<"card : "; output();
cout<<"zcl : "; zcl.output();
cout<<"ajh : "; ajh.output();
puts("#==================================================================================#");
#endif
for (int i=0;i<500;i++)
{
#ifdef DEBUG
cout<<i+1<<" : \n";
#endif
if (zcl.empty()){puts("ajh"); return 0;} zcl.pop();
if (ajh.empty()){puts("zcl"); return 0;} ajh.pop();
#ifdef DEBUG
cout<<"card : "; output();
cout<<"zcl : "; zcl.output();
cout<<"ajh : "; ajh.output();
puts("#==================================================================================#");
#endif
}
if (ajh.size()>zcl.size()) puts("zcl");
else if (ajh.size()==zcl.size()) puts("no winner");
else puts("ajh");
return 0;
} L. 正方形
一开始以为正方形一定和 轴平行,结果 WA 了。
正确做法是构建平行四边形,对每个平行四边形判定是不是正方形即可。
判定方法:看看四个点的连线是不是正好四个短两个长并且长的是短的的 倍。
Code:
using namespace std;
namespace Main
{
struct point{int x,y;point(int X=0,int Y=0){x=X; y=Y;}}a,b,c;
point Getans(const point& a,const point& b,const point& c){return point(a.x+c.x-b.x,a.y+c.y-b.y);}
bool exists(const point& q){return ((a.x==q.x)&&(a.y==q.y))||((b.x==q.x)&&(b.y==q.y))||((c.x==q.x)&&(c.y==q.y));}
inline double sqr(double x){return x*x;}
inline double dist(const point& a,const point& b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
bool equ(const double& x,const double& y){return x-y<1e-5;}
bool is_square(const point& a,const point& b,const point& c,const point& d)
{
double dis[9]={dist(a,b),dist(a,c),dist(a,d),dist(b,c),dist(b,d),dist(c,d)};
sort(dis,dis+6); reverse(dis,dis+6);
int k=dis[0];
return (equ(k,dis[1])&&equ(dis[2],dis[3])&&equ(dis[3],dis[4])&&equ(dis[4],dis[5])&&equ(k,dis[2]*sqrt(2)));
}
int main()
{
scanf("%d%d%d%d%d%d",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y);
point ans;
#define check {if (is_square(a,b,c,ans)){printf("%d %d",ans.x,ans.y); return 0;}}
ans=Getans(a,b,c); check;
ans=Getans(a,c,b); check;
ans=Getans(b,a,c); check;
ans=Getans(b,c,a); check;
ans=Getans(c,a,b); check;
ans=Getans(c,b,a); check;
return 0;
}
}
int main(){return Main::main();} M. 超市里的货物架
注意到答案必须呈
形式,并且重复一定会使得答案截断。
故直接暴力枚举即可,注意要去重。
Code:
using namespace std;
const int N=1005;
char a[N],b[N];
int n,m;
set<char> q;
int main()
{
scanf("%d%d%s%s",&n,&m,a,b);
// sort(a,a+n); sort(b,b+m); n=unique(a,a+n)-a; m=unique(b,b+m)-b;
// 因为在 set 里去重了,a 和 b 数组就不用去重了
for (int i=0;i<n;i++)
for (int j=0;j<m;j++)
if (a[i]==b[j]){q.insert(a[i]); break;}
printf("%d",int(q.size()));
return 0;
} 
京公网安备 11010502036488号