头像

何以解忧唯有AC_7


访客:192

离线:6小时前


活动打卡代码 AcWing 1204. 错误票据

//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include[HTML_REMOVED]

include[HTML_REMOVED]

using namespace std;
const int N = 11000;
int a[N];
int main()
{
int n, cnt = 0;
int x, y;
cin >> n;
while (cin >> a[cnt]);
sort(a, a + cnt - 1);
for (int i = 0; i < cnt - 1; i
)
if (a[i] == a[i + 1])
{
x = a[i];
break;
}
for(int i = 0;i<cnt - 1;i++)
if (a[i] + 1 != a[i + 1] && a[i] < a[i + 1])
{
y = a[i] + 1;
break;
}
cout << y << ” ” << x << endl;
}



活动打卡代码 AcWing 1245. 特别数的和

//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include[HTML_REMOVED]

using namespace std;
const int N = 10010;
int a[N];

inline int judge(int i)
{
int res;
while (i)
{
res = i % 10;
i /= 10;
if (res == 2 || res == 0 || res == 1 || res == 9) return 1;
}
return 0;
}
int main()
{
int n, sum = 0;
for (int i = 0; i < N; i)
a[i] = judge(i);
cin >> n;
for (int i = 1; i <= n; i
)
if (a[i])
sum += i;
cout << sum << endl;
}



活动打卡代码 AcWing 1210. 连号区间数

//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include[HTML_REMOVED]

include[HTML_REMOVED]

using namespace std;
const int N = 10010, INF = 100000000;
int n, a[N];
int main()
{
cin >> n;
for (int i = 0; i < n; i) cin >> a[i];
int res = 0;
for (int i = 0; i < n; i
)
{
int minv = INF, maxv = -INF;
for (int j = i; j < n; j)
{
minv = min(minv, a[j]);
maxv = max(maxv, a[j]);
if (maxv - minv == j - i) res
;
}
}
cout << res << endl;
}



活动打卡代码 AcWing 1214. 波动数列

//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

using namespace std;

const int N = 1010, MOD = 100000007;

int f[N][N];

int get_mod(int a, int b) // 求a除以b的正余数
{
return (a % b + b) % b;
}

int main()
{
int n, s, a, b;
cin >> n >> s >> a >> b;

f[0][0] = 1;
for (int i = 1; i < n; i ++ )
    for (int j = 0; j < n; j ++ )
        f[i][j] = (f[i - 1][get_mod(j - a * (n - i), n)] + f[i - 1][get_mod(j + b * (n - i), n)]) % MOD;

cout << f[n - 1][get_mod(s, n)] << endl;

return 0;

}



活动打卡代码 AcWing 1212. 地宫取宝

//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include [HTML_REMOVED]

include [HTML_REMOVED]

include [HTML_REMOVED]

using namespace std;

const int N = 55, MOD = 1000000007;

int n, m, k;
int w[N][N];
int f[N][N][13][14];

int main()
{
cin >> n >> m >> k;
for (int i = 1; i <= n; i )
for (int j = 1; j <= m; j
)
{
cin >> w[i][j];
w[i][j] ++ ;
}

f[1][1][1][w[1][1]] = 1;
f[1][1][0][0] = 1;

for (int i = 1; i <= n; i ++ )
    for (int j = 1; j <= m; j ++ )
    {
        if (i == 1 && j == 1) continue;
        for (int u = 0; u <= k; u ++ )
            for (int v = 0; v <= 13; v ++ )
            {
                int &val = f[i][j][u][v];
                val = (val + f[i - 1][j][u][v]) % MOD;
                val = (val + f[i][j - 1][u][v]) % MOD;
                if (u > 0 && v == w[i][j])
                {
                    for (int c = 0; c < v; c ++ )
                    {
                        val = (val + f[i - 1][j][u - 1][c]) % MOD;
                        val = (val + f[i][j - 1][u - 1][c]) % MOD;
                    }
                }
            }
    }

int res = 0;
for (int i = 0; i <= 13; i ++ ) res = (res + f[n][m][k][i]) % MOD;

cout << res << endl;

return 0;

}

作者:yxc
链接:https://www.acwing.com/activity/content/code/content/166751/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。



活动打卡代码 AcWing 1015. 摘花生

//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include[HTML_REMOVED]

include[HTML_REMOVED]

include[HTML_REMOVED]

using namespace std;
const int N = 110;
int n, m, w[N][N], f[N][N];

int main()
{
int T;
cin >> T;
while (T–)
{
cin >> n >> m;
for (int i = 1; i <= n; i)
for (int j = 1; j <= m; j
)
cin >> w[i][j];
memset(f, 0, sizeof f);
for (int i = 1; i <= n; i)
for (int j = 1; j <= m; j
)
f[i][j] = max(f[i - 1][j], f[i][j - 1]) + w[i][j];
cout << f[n][m] << endl;
}
}




//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include[HTML_REMOVED]

include[HTML_REMOVED]

using namespace std;
const int N = 1010;
int n, a[N], f[N];

int main()
{
cin >> n;
for (int i = 1; i <= n; i) cin >> a[i];
int res = 0;
for (int i = 1; i <= n; i
)
{
f[i] = 1;
for (int j = 1; j < i; j++)
if (a[i] > a[j])
f[i] = max(f[i], f[j] + 1);
res = max(res, f[i]);
}
cout << res << endl;
}



活动打卡代码 AcWing 2. 01背包问题

//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include[HTML_REMOVED]

using namespace std;

const int N = 1010;
int n, m, v[N], w[N], f[N][N];

int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i ) cin >> v[i] >> w[i];
for(int i = 1; i <= n; i
)
for(int j = 0; j <= m; j ++)
{
f[i][j] = f[i - 1][j];
if(j >= v[i])
f[i][j] = max(f[i][j], f[i - 1][j - v[i]] + w[i]);
}
cout << f[n][m] << endl;
}



活动打卡代码 AcWing 1216. 饮料换购

//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include[HTML_REMOVED]

using namespace std;

int main()
{
int n, res, sum;
cin >> n;
sum = n;
res = 0;
while (n >= 3)
{
res += n % 3;
n /= 3;
sum += n;
if (res != 0)
{
n += res;
res = 0;
}
}
cout << sum << endl;
}



活动打卡代码 AcWing 1205. 买不到的数目

//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int p = scan.nextInt();
int q = scan.nextInt();
System.out.println((p - 1) * (q - 1) - 1);
}
}