目录
G Limit
题意:
求导。
思路:
t<=5,直接暴力。
题解:
#include <bits/stdc++.h>
#define bbn 200005
#define maxint 2147483647
#define maxLLint 9223372036854775807
#define mod 1000000007 //1e9+7
const double eps=1e-7;
typedef long long int LL;
using namespace std;
LL n,t;
LL a[bbn],b[bbn];
LL dt[6];
LL q[6]= {1,1,2,6,24,120};
LL gcd(LL a,LL b)
{
return b!=0?gcd(b,a%b):a;
}
int main()
{
cin>>n>>t;
for(LL i=1; i<=n; i++)
{
cin>>a[i]>>b[i];
}
for(LL i=1; i<=5; i++)
{
for(LL j=1; j<=n; j++)
{
dt[i]+=q[i-1]*a[j]*pow(b[j],i);
}
if(i%2==0)
{
dt[i]*=-1;
}
}
bool judge=1;
for(LL i=1; i<=t-1; i++)
{
if(dt[i]!=0)
{
judge=0;
break;
}
}
if(judge)
{
if(dt[t]%q[t]==0)
{
printf("%lld",dt[t]/q[t]);
}
else
{
LL k=gcd(dt[t],q[t]);
printf("%lld/%lld",dt[t]/k,q[t]/k);
}
}
else
{
printf("infinity");
}
return 0;
}
J Leaking Roof
题意:
n*n的房顶(方格网),每个方格上有m毫升的雨,雨从高处到低处(相等时不会动),流到 h = 0 时,泄露下来。
给了每个方格的高度。
输出一段时间之后的方格网雨量。
思路:
遍历每一个点,对每一个点bfs(bfs和dfs好像混用了)。
模拟流水的过程和分配。
不用记录,反正只能从高处到低处。
用cout会出错...
题解:
#include <bits/stdc++.h>
#define bbn 200005
#define maxint 2147483647
#define maxLLint 9223372036854775807
#define mod 1000000007 //1e9+7
const double eps=1e-7;
typedef long long int LL;
using namespace std;
int n;
double m;
int h[501][501];
double store[501][501];
int xx[4]= {1,-1,0,0};
int yy[4]= {0,0,1,-1};
struct p
{
int x,y;
};
void bfs(double s,int x,int y)
{
if(h[x][y]==0)
{
store[x][y]+=s;
return ;
}
queue<p>q;
int cnt=0;
for(int i=0; i<=3; i++)
{
int dx=x+xx[i];
int dy=y+yy[i];
if(1<=dx&&dx<=n&&1<=dy&&dy<=n)
{
if(h[x][y]>h[dx][dy])
{
cnt++;
q.push({dx,dy});
}
}
}
while(!q.empty())
{
bfs(s/(double)cnt,q.front().x,q.front().y);
q.pop();
}
return;
}
void print()
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
printf("%lf ",store[i][j]);
//cout<<store[i][j]<<" ";
}
cout<<'\n';
}
}
int main()
{
cin>>n>>m;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
cin>>h[i][j];
}
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
bfs(m,i,j);
// cout<<"::"<<i<<"::"<<j<<'\n';
// print();
}
}
print();
return 0;
}
总结:
参赛资格都没有,呜呜呜...