 candy.

Hello word入门小萌新

1539  ℒℴѵℯ北陌离歌 jwh    myh123 Koschei    R.G莎   Crystal6829  Anohgy   tetean

candy.
22天前
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=200010;
int n;
int b[N];
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n;
memset(b,0,(n+1)*4);
for(int i=1;i<=n;i++)
{
int a;
cin>>a;
a=min(a,i);
int l=i-a+1,r=i;
b[l]=b[l]+1;b[r+1]=b[r+1]-1;
}
for(int i=1;i<=n;i++)
b[i]=b[i]+b[i-1];
for(int i=1;i<=n;i++)
{
if(b[i]>0)
cout<<"1"<<" ";
else cout<<"0"<<" ";
}
cout<<endl;
}
return 0;
}


candy.
29天前
#include <cstdio>
#define N 114514
using namespace std;

int n, ave, cnt, s[N];
long long ans;

int main ()
{
scanf ("%d", &n);
for (int i = 1; i <= n; i ++)
{
scanf ("%d", &s[i]), s[i] += s[i - 1];
}
if (s[n] % 3)
{
puts ("0");
return 0;
}
ave = s[n] / 3;
for (int i = 1; i < n; i ++)
{
if (s[i] == ave << 1)
{
ans += cnt;
}
cnt += s[i] == ave;
}
printf ("%lld", ans);
return 0;
}


candy.
1个月前

candy.
1个月前

272.最长公共上升子序列

### 题目描述

#### 输入格式

第一行包含一个整数 N，表示数列 A，B 的长度。



#### 输出格式

输出一个整数，表示最长公共上升子序列的长度。


#### 输入样例

4
2 2 1 3
2 1 2 3


#### 输出样例

2


#### 数据范围

1≤N≤3000 ,序列中的数字均不超过 2^31-1。


### 这是两个DP模型的结合版：

LIS (最长上升子序列，Longest Increasing Subsequence)

LCS (最长公共子序列，Longest Common Subsequence)

LCIS (最长公共上升子序列，Longest Common Increasing Subsequence)

#### C++ 代码

#include<bits/stdc++.h>
using namespace std;
int f,a,b;
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
for(int i=1;i<=n;i++){
int maxk=1;
for(int j=1;j<=n;j++){
if(a[i]!=b[j]){
f[i][j]=f[i-1][j];
}
if(a[i]==b[j]){
f[i][j]=max(maxk,1);
}
if(b[j]<a[i]){
maxk=max(maxk,f[i-1][j]+1);
}
}
}
int ans=0;
for(int i=1;i<=n;i++){
ans=max(ans,f[n][i]);
}
cout<<ans<<endl;
return 0;
}


### 一个萌新，请多多关照

candy.
1个月前

candy.
1个月前

AcWing【集日历瓜分10000AC币活动】赠送1月日历！

AcWing【集日历瓜分10000AC币活动】赠送2月日历！

AcWing【集日历瓜分10000AC币活动】赠送3月日历！

AcWing【集日历瓜分10000AC币活动】赠送4月日历！

AcWing【集日历瓜分10000AC币活动】赠送5月日历！

AcWing【集日历瓜分10000AC币活动】赠送6月日历！

AcWing【集日历瓜分10000AC币活动】赠送7月日历！

AcWing【集日历瓜分10000AC币活动】赠送8月日历！

AcWing【集日历瓜分10000AC币活动】赠送9月日历！

AcWing【集日历瓜分10000AC币活动】赠送11月日历！

AcWing【集日历瓜分10000AC币活动】赠送12月日历！

candy.
2个月前

8.二维费用的背包问题

### 题目描述

#### 输入格式

第一行三个整数，N,V,M，用空格隔开，分别表示物品件数、背包容积和背包可承受的最大重量。



#### 输出格式

输出一个整数，表示最大价值。


#### 输入样例

4 5 6
1 2 3
2 4 4
3 4 5
4 5 6


#### 输出样例

8


#### 数据范围

0<N≤1000
0<V,M≤100
0<vi,mi≤100
0<wi≤1000


（背包）DP

### 时间复杂度

O(nmk)

#### C++ 代码

#include<iostream>
using namespace std;
int dp,w,c,v,m,n,vv;
int main(){
cin>>n>>vv>>m;
for(int i=1;i<=n;i++){
cin>>v[i]>>w[i]>>c[i];
}
for(int i=1;i<=n;i++){
for(int j=m;j>=w[i];j--){
for(int k=vv;k>=v[i];k--){
dp[j][k]=max(dp[j][k],dp[j-w[i]][k-v[i]]+c[i]);
}
}
}
cout<<dp[m][vv]<<endl;
return 0;
}


### 一个萌新，请多多关照

candy.
2个月前
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
ll n,e,d;
cin>>n>>e>>d;
ll b=e*d-n-2;
ll san=b*b-4*n;
if(san<0) cout<<"NO"<<'\n';
else{
ll x1=(-b+sqrt(san))/2;
ll y1=n/x1;
if(x1>=y1) swap(x1,y1);
if(x1*y1!=n||(x1-1)*(y1-1)+1!=e*d) cout<<"NO\n";
else cout<<x1<<' '<<y1<<'\n';
}
}
return 0;
}


candy.
2个月前

### 题目描述

Farmer John has gone to town to buy some farm supplies. Being a very efficient man, he always pays for his goods in such a way that the smallest number of coins changes hands, i.e., the number of coins he uses to pay plus the number of coins he receives in change is minimized. Help him to determine what this minimum number is.

FJ wants to buy T (1 ≤ T ≤ 10,000) cents of supplies. The currency system has N (1 ≤ N ≤ 100) different coins, with values V1, V2, …, VN (1 ≤ Vi ≤ 120). Farmer John is carrying C1 coins of value V1, C2 coins of value V2, ...., and CN coins of value VN (0 ≤ Ci ≤ 10,000). The shopkeeper has an unlimited supply of all the coins, and always makes change in the most efficient manner (although Farmer John must be sure to pay in a way that makes it possible to make the correct change).

John想要买价值为T的东西。有N(1<=n<=100)种货币参与流通，面值分别为V1,V2..Vn (1<=Vi<=120)。John有Ci个面值为Vi的硬币(0<=Ci<=10000)。

#### 输入格式

Line 1: Two space-separated integers: N and T.

Line 2: N space-separated integers, respectively V1, V2, ..., VN coins (V1, ...VN)

Line 3: N space-separated integers, respectively C1, C2, ..., CN


#### 输出格式

Line 1: A line containing a single integer, the minimum number of coins involved in a payment and change-making. If it is impossible for Farmer John to pay and receive exact change, output -1.


#### 输入样例

3 70
5 25 50
5 2 1


#### 输出样例

3


#### C++ 代码

#include<bits/stdc++.h>
using namespace std;
int f,g;
//f[i]、g[i]分别表示John和店长付i元钱最少需要用的硬币
int v,c;//如题意所示
int main(){
int n,t;
scanf("%d %d",&n,&t);
for(int i=1;i<=n;i++){
scanf("%d",&v[i]);//输入每个钱币的面值
}
int sum=0,mx=10000;
for(int i=1;i<=n;i++){//输入每个钱币的钱总量
scanf("%d",&c[i]);
sum+=c[i]*v[i];//求农夫拥有的钱总量
//mx=max(mx,v[i]*v[i]);
}
if(sum<t){//买不起，退了
printf("-1\n");
return 0;
}
memset(g,0x3f,sizeof(g));
memset(f,0x3f,sizeof(f));
g=0;
f=0;
for(int i=1;i<=n;i++){
for(int j=v[i];j<=mx;j++){//Rob找j元钱所用的最小钱数
g[j]=min(g[j],g[j-v[i]]+1);
}
}
//实际上应该是g[i][j]=min(g[i-1][j],g[i][j-v[i]+1])
//g[i][j]表示考虑到第i个物品支付j元的最少硬币数
//但是因为第一维存储的信息用不到
//且更新前g[i][j]记录的就是g[i-1][j]的信息
//所以可以只用一维
for(int i=1;i<=n;i++){
for(int j=1;j<=c[i];j<<=1){//二进制拆分的思想
for(int k=t+mx;k>=j*v[i];k--){
//倒过来更新(实际上是拆分成01背包的形式）
f[k]=min(f[k],f[k-j*v[i]]+j);
}
c[i]-=j;//相当于用拆分的物品进行了一次更新，要从数量中减去
}
if(c[i]){//还有剩余的
for(int k=t+mx;k>=c[i]*v[i];k--){
f[k]=min(f[k],f[k-c[i]*v[i]]+c[i]);
}
}
}
int ans=0x3f3f3f3f;
for(int i=t;i<=t+mx;i++){
ans=min(ans,f[i]+g[i-t]);
}
printf("%d\n",ans==0x3f3f3f3f?-1:ans);
return 0;
}


### 一个萌新，请多多关照

candy.
2个月前
#include <bits/stdc++.h>
using namespace std;

int main()
{
int a, b, res = 1;
scanf("%d%d", &a, &b);
if (a == 1) return 0 & puts("1");
if (b >= 30) return 0 & puts("-1");
for (int i = 1; i <= b; i ++ )
{
if (res * 1ll * a > 1e9) return 0 & puts("-1");
res *= a;
}
printf("%d", res);
return 0;
}