视频题解戳这里
A. Roman and Browser
解题思路:暴力枚举就可以出答案。
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f;
int n,k,xx=0,yy=0;
int a[1000];
int main(){
std::ios::sync_with_stdio(0);
cin>>n>>k;
for(int i=1;i<=n;++i){
cin>>a[i];
if(a[i]==-1){
xx++;
}
else{
yy++;
}
}
int ans=-1;
int b[1000];
for(int i=1;i<=k;++i){
int tx=xx,ty=yy;
memcpy(b,a,1000*sizeof(int));
for(int j=i;j<=n;j+=k){
if(a[j]==1){
ty--;
}
else{
tx--;
}
}
ans=max(ans,abs(tx-ty));
}
cout<<ans<<endl;
return 0;
}
B. Build a Contest
解题思路:这也是一个比较简单的模拟题,只要一直记录现在不同数的个数,和不同种类的数出现的次数,就可以了。
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f;
const int maxn=1e5+5;
int n,m;
int a[maxn];
int num[maxn];
int difnum;
int main(){
std::ios::sync_with_stdio(0);
cin>>n>>m;
for(int i=0;i<m;++i){
cin>>a[i];
}
int difnum=0;
for(int i=0;i<m;++i){
if(num[a[i]]==0){
difnum++;
}
num[a[i]]++;
if(difnum==n){
cout<<1;
for(int j=1;j<=n;++j){
num[j]--;
if(num[j]==0){
difnum--;
}
}
}
else{
cout<<0;
}
}
return 0;
}
C. NN and the Optical Illusion
解题思路:一道非常简单的几何题,自己画个图用个余弦定理建立个等式就可以求出。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const double pi=acos(-1);
int main() {
double n,r;
cin>>n>>r;
double res=r*(sin(pi/n))/(1-sin(pi/n));
printf("%.7lf\n",res);
return 0;
}
D. Dasha and Chess
解题思路:这是一道交互题,而且题干相当的长,学长说就是就是题目难懂,懂了就是sb题,代码在这可以看看。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
int dx[] = {-1, -1, 1, 1};
int dy[] = {-1, 1, 1, -1};
int nums[maxn];
int G[maxn][maxn];
int xx[maxn];
int yy[maxn];
int nx, ny;
int get_location(int x, int y) {
if (x < nx && y < ny) {
return 0;
} else if (x < nx && y > ny) {
return 1;
} else if (x > nx && y > ny) {
return 2;
} else {
return 3;
}
}
int main() {
cin >> nx >> ny;
for (int i = 1; i <= 666; ++i) {
cin >> xx[i] >> yy[i];
G[xx[i]][yy[i]] = 1;
nums[get_location(xx[i], yy[i])]++;
}
int flag = 0;
int tmpsum = 0;
for (int i = 0; i < 4; ++i) {
int tmp = nums[i] + nums[(i+1)%4] + nums[(i+3)%4];
if (tmp > tmpsum) {
tmpsum = tmp;
flag = i;
}
}
for (int i = 1; i <= 2000; ++i) {
int tx = nx + dx[flag];
int ty = ny + dy[flag];
if (tx < 1 || tx > 999)
tx = nx;
if (ty < 1 || ty > 999)
ty = ny;
if (G[tx][ty] == 1)
ty = ny;
nx = tx;
ny = ty;
cout << nx << " " << ny << endl;
cout.flush();
int k, cx, cy;
cin >> k >> cx >> cy;
if (k <= 0)
break;
G[xx[k]][yy[k]] = 0;
G[cx][cy] = 1;
xx[k] = cx;
yy[k] = cy;
}
return 0;
}
E. Andrew and Taxi
这题打cf时没有做出来,赛后才知道这是一道二分+拓扑,单独写一下。