- wsh 的博客
8月week2Day 3总结
- @ 2024-8-14 20:19:01
作者附:今天是最后一天复赛复习了www但初赛3天60+可以继续复习复赛捏 额要加油§( ̄▽ ̄)§
T1小苹果(数学)
总结(自己)
a了 但想到这个方法的时候想了挺久 下次数学题要尽快想到方法
思路
3个为一组 每次拿走每组的队头 就是
附Ac代码
#include<bits/stdc++.h>
using namespace std;
int n,d;
bool o;
void fropn(string a){
string t1=a+".in",t2=a+".out";
freopen(t1.c_str(),"r",stdin);
freopen(t2.c_str(),"w",stdout);
}
int main()
{
fropn("apple");
cin>>n;
int i;
for(i=1;n;i++)
{
int s;
if(n%3==0) s=n/3;
else s=n/3+1;
if(n%3==1&&o==0){
d=i;
o=1;
}
n-=s;
}
cout<<i-1<<" "<<d;
return 0;
}
T2公路(贪心)
总结(自己)
考试也A了 蛋柿开始想到了dp 用₯之前要想后效性
思路
贪心找到第一个当前价钱比现在便宜的地方 然后走就完了
附Ac代码
#include<bits/stdc++.h>
using namespace std;
long long n,d,v[100010],ans,a[100010],qz[100010],y;
void fropn(string a){
string t1=a+".in",t2=a+".out";
freopen(t1.c_str(),"r",stdin);
freopen(t2.c_str(),"w",stdout);
}
int main()
{
fropn("road");
cin>>n>>d;
for(int i=1;i<=n-1;i++){
cin>>v[i];
qz[i]=qz[i-1]+v[i];
}
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<n;){
int j=i+1;
while(a[i]<a[j]&&j<n){
j++;
}
// cout<<j<<" "<<i<<" ";
long long ju=qz[j-1]-qz[i-1];
// cout<<ju<<endl;
if(y>ju) y-=ju;
else{
ju-=y;
if(ju%d==0){
ans+=ju/d*a[i];
y=0;
}
else{
ans+=(ju/d+1)*a[i];
y=d-(ju%d);
}
}
i=j;
}
cout<<ans;
return
}
T3一元二次方程(模拟)
总结(自己)
看不懂一点 但按公式能50 wwww
思路
大大大大大****模拟
附Ac代码:
#include<bits/stdc++.h>
using namespace std;
int tt,m;
void fropn(string a){
string t1=a+".in",t2=a+".out";
freopen(t1.c_str(),"r",stdin);
freopen(t2.c_str(),"w",stdout);
}
int gcd(int a,int b)
{
if(!b) return a;
return gcd(b,a%b);
}
int main()
{
fropn("uqe");
cin>>tt>>m;
while(tt--)
{
int a,b,c;
cin>>a>>b>>c;
if(a<0){
a*=-1;
b*=-1;
c*=-1;
}
int s=b*b-4*a*c;
if(s<0){
cout<<"NO"<<endl;
continue;
}
else if(s==0)
{
int x=(-b)/(2*a);
if((-b)%(2*a)==0){
cout<<x<<endl;
}
else{
int cd=gcd(abs(b),abs(2*a));
b=(-b)/cd;
a=(2*a)/cd;
if(a==1) cout<<b<<endl;
else cout<<b<<'/'<<a<<endl;
}
}
else{
int x=((-b)+s)/(2*a);
if(int(sqrt(s))*int(sqrt(s))==s){
int t=sqrt(s)-b;
if(t%(2*a)==0) cout<<t/(2*a)<<endl;
else{
int cd=gcd(abs(t),abs(2*a));
t=t/cd;
a=(2*a)/cd;
cout<<t<<'/'<<a<<endl;
}
}
else{
int c,d;
int cd=gcd(abs(-b),abs(2*a));
c=(-b)/cd;
d=(2*a)/cd;
if(c!=0){
if(d==1) cout<<c<<'+';
else cout<<c<<'/'<<d<<'+';
}
int k,r;
for(int i=sqrt(s);i>=1;i--){
if(s%(i*i)==0)
{
k=i;
r=s/(i*i);
break;
}
}
if(k%(2*a)==0){
if(k/(2*a)==1) cout<<"sqrt("<<r<<")"<<endl;
else cout<<k/(2*a)<<"*sqrt("<<r<<")"<<endl;
}
else{
if(k/gcd(2*a,k)==1) cout<<"sqrt("<<r<<")/"<<2*a/gcd(2*a,k)<<endl;
else cout<<k/gcd(2*a,k)<<"*sqrt("<<r<<")/"<<2*a/gcd(2*a,k)<<endl;
}
}
}
}
return 0;
}