day1
tile 铺瓷砖
数学
#include
#include
#include
#include
#include
#define LL long long
using namespace std;
LL read(){
LL x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while('0'<=ch&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
LL T;
LL gcd(LL x,LL y){
if(y==0) return x;
else return gcd(y,x%y);
}
LL lcm(LL x,LL y){
return x/gcd(x,y)*y;
}
int main(){
freopen("tile.in","r",stdin);
freopen("tile.out","w",stdout);
T=read();
LL a,b,c,d,e,f,g;
while(T--){
a=read();b=read();c=read();d=read();
e=a*d/gcd(b,d);
f=c*b/gcd(b,d);
g=lcm(e,f)/e;
if(a*g%b==0) printf("%lld\n",a*g/b);
else printf("%lld/%lld\n",a*g/gcd(a*g,b),b/gcd(a*g,b));
}
fclose(stdin);fclose(stdout);
return 0;
}
question 小Y的问题
#include
#include
#define LL long long
using namespace std;
LL n,x,y,z,num,dg[300000],fl[300000][4],ans;
LL ff[300000][4],sum,flagg;
LL head[1500000],next[1500000],to[1500000],v[1500000],ans1;
void add1(LL a,LL b,LL c)
{
num++;
next[num]=head[a];
to[num]=b;
v[num]=c;
head[a]=num;
}
LL read(){
LL x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while('0'<=ch&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
int main()
{
freopen("question.in","r",stdin);
freopen("question.out","w",stdout);
n=read();
for(int i=1;i<=n-1;i++)
{
x=read();y=read();z=read();
add1(x,y,z);
add1(y,x,z);
dg[x]++;
for(int j=1;j<=3;j++)
{
if(z>fl[x][j])
{
for(int k=3;k>j;k--)
{
fl[x][k]=fl[x][k-1];
ff[x][k]=ff[x][k-1];
}
fl[x][j]=z;ff[x][j]=y;break;
}
}
dg[y]++;
for(int j=1;j<=3;j++)
{
if(z>fl[y][j])
{
for(int k=3;k>j;k--)
{
fl[y][k]=fl[y][k-1];
ff[y][k]=ff[y][k-1];
}
fl[y][j]=z;ff[y][j]=x;break;
}
}
}
for(int i=1;i<=n;i++)
{
if(dg[i]>=3)
{
LL qwq=dg[i]-1;
qwq=(qwq*(qwq-1))/2;
for(int j=head[i];j!=0;j=next[j])
{
int p=to[j];
if(dg[p]>=2)
{
LL fas;
fas=qwq*(dg[p]-1);
ans+=fas;
sum=0;flagg=0;
for(int k=1;k<=3;k++)
{
if(ff[i][k]!=p)
{
sum+=fl[i][k];
flagg++;
if(flagg==2) break;
}
}
sum+=v[j];
for(int k=1;k<=3;k++)
{
if(ff[p][k]!=i)
{
sum+=fl[p][k];
break;
}
}
ans1=max(sum,ans1);
}
}
}
}
cout<
day2
transact 业务办理
贪心
#include
#include
#include
#include
#include
#define LL long long
using namespace std;
LL read(){
LL x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
const int N=1e5+7;
struct people{
LL t,d;
#define t(x) a[x].t
#define d(x) a[x].d
}a[N];
LL n,sum=0,mx=0;
bool cmp(const people &x,const people &y){
return x.dd(i)) mx=max(mx,sum-d(i));
}
printf("%lld",mx);
fclose(stdin);fclose(stdout);
return 0;
}
pass 传球接力
#include
#include
#include
#include
#include
#include
#define LL long long
#define MOD 1000000007
using namespace std;
int n,i,j,a[500005],d[500005],rd[500005],vis[500005],cyc[500005],len,sum;
int unrd[500005],rt,l,maxn[500005],k;
LL ans;
int main()
{
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d%d",&a[i],&d[i]);
rd[a[i]]++;
}
for(i=1;i<=n;i++) if(!rd[i]) unrd[++rt]=i;
while(l