9.19吉比特笔试第一题
吉比特笔试第一题多项式计算题,明明跟着测试案例敲在自己电脑上运行答案是正确的,到牛客笔试网上就错了(输出的值没错,但不知道为什么显示错误)。写完第二题直接没看第三题一直在改第一题,半小时没发现问题在哪。。。有无通过的大佬帮忙看看,不然要睡不着觉了
// ================= 代码 ================= //
#include
using namespace std;
const int MOD = 10000009;
const int Number = 233;
using ll = long long;
void oper(vector> &grid, int m, vector optNums, int l, int r)
{
for (int i = l; i <= r; ++i)
{
if (m % 2 == 0) // 偶操作 +
{
for (int j = 0; j < optNums.size(); ++j)
{
if (j > grid[i].size() - 1)
{
grid[i].push_back(optNums[j]);
} else {
grid[i][j] += optNums[j];
}
}
} else { // 奇操作 -
for (int j = 0; j < optNums.size(); ++j)
{
if (j > grid[i].size() - 1)
{
grid[i].push_back(-optNums[j]);
} else {
grid[i][j] -= optNums[j];
}
}
}
}
}
int main(int argc, char const *argv[])
{
int n, d, m;
cin >> n >> d >> m;
vector> grid(n + 1);
for (int i = 1; i <= n; ++i)
{
int p;
cin >> p;
for (int k = 0; k <= p; ++k)
{
int temp;
cin >> temp;
grid[i].push_back(temp);
}
}
for (int i = 1; i <= m; ++i)
{
int p, l, r;
cin >> p >> l >> r;
vector optNums(p + 1);
for (int i = 0; i <= p; ++i)
{
cin >> optNums[i];
}
oper(grid, i, optNums, l, r);
}
// 计算结果
for (int i = 1; i <= n; ++i)
{
ll sum = 0;
for (int k = 0; k < grid[i].size(); ++k)
{
sum += grid[i][k] * pow(Number, k);
sum %= MOD;
}
cout << sum << " ";
}
cout << endl;
return 0;
}
// ================= 代码 ================= //
#吉比特笔试#
// ================= 代码 ================= //
#include
using namespace std;
const int MOD = 10000009;
const int Number = 233;
using ll = long long;
void oper(vector
{
for (int i = l; i <= r; ++i)
{
if (m % 2 == 0) // 偶操作 +
{
for (int j = 0; j < optNums.size(); ++j)
{
if (j > grid[i].size() - 1)
{
grid[i].push_back(optNums[j]);
} else {
grid[i][j] += optNums[j];
}
}
} else { // 奇操作 -
for (int j = 0; j < optNums.size(); ++j)
{
if (j > grid[i].size() - 1)
{
grid[i].push_back(-optNums[j]);
} else {
grid[i][j] -= optNums[j];
}
}
}
}
}
int main(int argc, char const *argv[])
{
int n, d, m;
cin >> n >> d >> m;
vector
for (int i = 1; i <= n; ++i)
{
int p;
cin >> p;
for (int k = 0; k <= p; ++k)
{
int temp;
cin >> temp;
grid[i].push_back(temp);
}
}
for (int i = 1; i <= m; ++i)
{
int p, l, r;
cin >> p >> l >> r;
vector
for (int i = 0; i <= p; ++i)
{
cin >> optNums[i];
}
oper(grid, i, optNums, l, r);
}
// 计算结果
for (int i = 1; i <= n; ++i)
{
ll sum = 0;
for (int k = 0; k < grid[i].size(); ++k)
{
sum += grid[i][k] * pow(Number, k);
sum %= MOD;
}
cout << sum << " ";
}
cout << endl;
return 0;
}
// ================= 代码 ================= //
#吉比特笔试#
全部评论
grid[i][j] -= optNums[j];
grid[i][j] += optNums[j];没取模,如果ans变成负数,就错误了
相关推荐
腾讯 测试开发 25x15 大专
点赞 评论 收藏
分享