2018/12/14周五集训队第九次测试赛补题题解

A - Paper Airplanes CodeForces - 965A (数学)

先算出每个人要用几张纸,然后再算出总共要用几张纸,然后计算用多少包纸

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll k,n,s,p;
  cin>>k>>n>>s>>p;
  ll t;
  if(n%s==0)
  t=n/s;
  else
  t=n/s+1;
  ll jk=k*t;
  ll ans;
  if(jk%p==0)
  ans=jk/p;
  else
  ans=jk/p+1;
  cout<<ans;
}

B - Battleship CodeForces - 965B(待填坑)

待填坑

C - Petya and Origami CodeForces - 1080A(数学)

这个肯定都没问题,直接算就行

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n,k;
  cin>>n>>k;
  ll red=2*n;
  ll green=5*n;
  ll blue=8*n;
  ll sum=0;
  if(red%k==0)
  sum+=red/k;
  else
  sum+=red/k+1;
  if(blue%k==0)
  sum+=blue/k;
  else
  sum+=blue/k+1;
  if(green%k==0)
  sum+=green/k;
  else
  sum+=green/k+1;
  cout<<sum;
}

D - Margarite and the best present CodeForces - 1080B(数学)

数据过大枚举应该是要卡超时

应该去寻找一种直接的数学计算方法

解法

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll q;
  cin>>q;
  while(q--)
  {
    ll l,r;
    cin>>l>>r;
    if(l==r)
    {
      if(l%2!=0)
      cout<<-l<<"
";
      else
      cout<<l<<"
";
    }
    else
    {
      if(l%2!=0)
      {
        ll t=r-l+1;
        if(t%2==0)
        cout<<(t/2)<<"
";
        else
        cout<<(t/2)-r<<"
";
      }
      else
      {
        ll t=r-l+1;
        if(t%2==0)
        cout<<-(t/2)<<"
";
        else
        cout<<r-(t/2)<<"
";
      }
    }
  }
}

E - Masha and two friends CodeForces - 1080C (数学+思维)

这个题实在是太有意思了,太巧妙了。。

解法








代码

#include <bits/stdc++.h>
using namespace std;
long long cdiv(long long x,long long y)
{
  return x/y+(x%y>0);
}
long long w(long long a,long long b)
{
  return cdiv(a,2)*cdiv(b,2)+(a/2)*(b/2);
}
long long W(long long x1,long long y1,long long x2,long long y2)
{
  return w(x2,y2)-w(x2,y1-1)-w(x1-1,y2)+w(x1-1,y1-1);
}
long long B(long long x1,long long y1,long long x2,long long y2)
{
  return (y2-y1+1)*(x2-x1+1)-W(x1,y1,x2,y2);
}
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin>>t;
  while(t--)
  {
    int x1,x2,x3,x4,y1,y2,y3,y4;
    long long n,m;
    cin>>n>>m;
    cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
    long long white=W(1,1,m,n);
    long long black=B(1,1,m,n);
    white+=B(x1,y1,x2,y2);
    black-=B(x1,y1,x2,y2);
    white-=W(x3,y3,x4,y4);
    black+=W(x3,y3,x4,y4);
    if(max(x1,x3)<=min(x2,x4)&&max(y1,y3)<=min(y2,y4))
    {
      white = white - B(max(x1,x3),max(y1,y3),min(x2,x4),min(y2,y4));
      black = black + B(max(x1,x3),max(y1,y3),min(x2,x4),min(y2,y4));
    }
    cout<<white<<" "<<black<<"
";
  }
}
原文地址:https://www.cnblogs.com/baccano-acmer/p/10138237.html