五题菜狗…
那个自习室真是有毒..坐了一下子马上就感冒了..头痛…
A Wasserstein Distance
这题也是搞不懂,一开始狂wa,迷迷糊糊的.
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
int a[MAXN],b[MAXN],c[MAXN];
int main(int argc ,char const *argv[])
{
#ifdef noob
freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
#endif
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
set<LL > s;
s.clear();
for (int i = 0; i < n; ++i)
{
a[i] = b[i] = c[i] = 0;
scanf("%lld",&a[i]);
}
for (int i = 0; i < n; ++i)
{
scanf("%lld",&b[i]);
}
for (int i = 0; i < n; ++i)
{
if(a[i]>b[i])
{
s.insert(i);
c[i] = a[i]-b[i];
}
}
//cerr<<"sad"<<endl;
LL ans = 0;
for (int i = 0; i < n; ++i)
{
// debug(a[i]);
// debug(b[i]);
if(a[i]<b[i])
{
int need = b[i]-a[i];
//debug(need);
while(1)
{
int st = *s.begin();
// debug(c[st]);
// debug(need);
if(c[st]>need)
{
ans += abs(i-st)*need;
c[st]-=need;
break;
}
else
{
ans += abs(i-st)*c[st];
need-=c[st];
c[st] = 0;
s.erase(s.find(st));
}
if(need==0) break;
}
}
}
cout<<ans<<endl;
}
return 0;
}
E 小Y吃苹果
签到.
#include <iostream>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
int main(int argc ,char const *argv[])
{
#ifdef noob
freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
#endif
int n;
cin>>n;
int ans = 1;
for (int i = 0; i < n; ++i)
{
ans *= 2;
}
cout<<ans<<endl;
return 0;
}
F 1 + 2 = 3?
打表找规律,递归.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define debug(x) //std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
vector<LL > have[70];
LL fab[100],ans = 0,sum[100];
LL qm(LL a,LL b)
{
LL res = 1;
while(b)
{
if(b&1) res = res*a;
a*=a;
b>>=1;
}
return res;
}
void dfs(LL n)
{
if(n==0) return;
int p = lower_bound(sum, sum+70, n)-sum;
if(sum[p]!=n) p--;
debug(sum[p]);
debug(n);
ans += qm(2,p);
debug(ans);
if(n!=1)
dfs(n-sum[p]);
}
int main(int argc ,char const *argv[])
{
#ifdef noob
freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
#endif
fab[0] = fab[1] = fab[2] = 1;
for (int i = 0; i < 2; ++i)
{
for (int j = i+2; j < 70; ++j)
have[j].push_back(fab[i]);
}
sum[1] = 0,sum[1] = 2,sum[2] = 3;
for (int i = 3; i < 68; ++i)
{
fab[i] = fab[i-1]+fab[i-2];
sum[i] =fab[i]+sum[i-1];
for (int j = i+2; j < 70; ++j)
{
have[j].push_back(fab[i]);
}
// debug(i);
// debug(fab[i]);
// debug(sum[i]);
}
int t;
cin>>t;
while(t--)
{
LL n;
cin>>n;
ans = 0;
dfs(n);
cout<<ans<<endl;
}
return 0;
}
I 二数
水题
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
int main(int argc ,char const *argv[])
{
#ifdef noob
freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
#endif
int t;
cin>>t;
while(t--)
{
string str,ans;
str.clear();
ans.clear();
cin>>str;
if(str=="1")
{
cout<<"0"<<endl;
continue;
}
bool fd = false;
for (int i = 0; i < str.length(); ++i)
{
if((str[i]-'0')&1==1)
{
fd = true;
ans = str.substr(0,i);
if(str[i]=='9')
{
for (int j = 0;j < str.length()-i; ++j)
{
ans.push_back('8');
}
break;
}
bool up = false;
for (int j = i+1; j < str.length(); ++j)
{
if((str[j]-'0')>4)
{
up = true;
break;
}
else if((str[j]-'0')<4)
break;
}
if(up)
ans.push_back(str[i]+1);
else if(str[i]=='1'&&i==0)
;
else
ans.push_back(str[i]-1);
if(up)
{
for (int j = 0; j < str.length()-i-1; ++j)
{
ans.push_back('0');
}
}
else
{
for (int j = 0; j < str.length()-i-1; ++j)
{
ans.push_back('8');
}
}
break;
}
}
if(fd)
cout<<ans<<endl;
else
cout<<str<<endl;
}
return 0;
}
L K序列
我感觉这题蛮难的啊…为什么呢..
处理取模,然后dp最少获得溢出的数量.
#include <iostream>
#include <vector>
using namespace std;
#define debug(x) //std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
LL a[MAXN];
vector<LL > rem;
vector<vector<LL > > dp;
int main(int argc ,char const *argv[])
{
#ifdef noob
freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
#endif
LL n,k,ans = 0,dap = 0;
cin>>n>>k;
for (int i = 0; i < n; ++i)
{
scanf("%d",a+i);
if(a[i]%k==0) ans++;
else rem.push_back(a[i]%k);
dap+=a[i]%k;
dap%=k;
}
//if(ans==0) return cout<<0<<endl,0;
if(rem.size()==0) return cout<<ans<<endl,0;
if(dap==0) return cout<<n<<endl,0;
dp.resize(rem.size());
for (int i = 0; i < rem.size(); ++i)
dp[i].resize(k+1);
dp[0][rem[0]] = 1;
dp[0][0] = 1;
for (int i = 0; i < rem.size()-1; ++i)
{
for (int j = 0; j <= k; ++j)
{
if(dp[i][j])
{
dp[i+1][j] = 1;
dp[i+1][(j+rem[i+1])%k] = 1;
}
}
}
debug(dap);
for (int i = 0; i < rem.size(); ++i)
{
if(dp[i][dap]==1)
{
debug(i);
ans = n-i-1;
break;
}
}
cout<<ans<<endl;
return 0;
}