#B - Memory
注意浮点数
代码
#include<bits/stdc++.h>
using namespace std;
int a[1000000];
int main()
{
int n;
cin>>n;
int x=0;
double flag=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
x+=a[i];
if(x>0) cout<<"+";
else if(x<0) cout<<"-";
else
{
if(flag==0) cout<<"0";
else if(flag<0) cout<<"-";
else cout<<"+";
}
if(x%2!=0)
flag+=1.0*x/2.0-x/2;
x/=2;
}
return 0;
}
#L - Palm Island
冒泡思想
代码
#include <iostream>
#include <algorithm>
using namespace std;
int a[10002], b[10002], c[10002];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++) {
cin >> b[i];
c[b[i]] = i;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - 1; j++) {
if (c[a[j]] > c[a[j + 1]]) {
cout << "2";
swap(a[j], a[j + 1]);
} else
cout << "1";
}
cout << "1";
}
cout << "\n";
}
int main() {
int t;
cin >> t;
while (t--)
solve();
return 0;
}
#M - Painter
代码
# include <bits/stdc++.h>
# define int long long
using namespace std;
struct rect
{
int x,y;
int x1,y1;
int r;
int flag;
char l;
} d[2100];
int check(int u,int v,int x,int y,int r)
{
if((x-u)*(x-u)+(y-v)*(y-v)<=r*r)
{
return 1;
}
else
{
return 0;
}
}
int check1(int u,int v,int x,int x1,int y,int y1)
{
if(u>=x&&u<=x1&&v>=y&&v<=y1)
{
return 1;
}
else
{
return 0;
}
}
signed main()
{
int n;
cin>>n;
int m=0;
for(int i=1; i<=n; i++)
{
string s;
cin>>s;
if(s=="Circle")
{
cin>>d[m].x>>d[m].y>>d[m].r;
d[m].flag=1;
cin>>d[m].l;
m++;
}
else if(s=="Rectangle")
{
cin>>d[m].x>>d[m].y>>d[m].x1>>d[m].y1;
d[m].flag=2;
cin>>d[m].l;
m++;
}
else
{
int x,y,x1,y1;
cin>>x>>y>>x1>>y1;
for(int i=y1; i>=y; i--)
{
for(int j=x; j<=x1; j++)
{
char o='.';
for(int z=m-1; z>=0; z--)
{
if(d[z].flag==1)
{
if(check(j,i,d[z].x,d[z].y,d[z].r))
{
o=d[z].l;
break;
}
}
else if(d[z].flag==2)
{
if(check1(j,i,d[z].x,d[z].x1,d[z].y,d[z].y1))
{
o=d[z].l;
break;
}
}
}
cout<<o;
}
cout<<endl;
}
}
}
}