伪的全解…其实避过了第五题…以后有时间再补叭
先是水的第一题
#include<iostream>
using namespace std;
int a[600][600];
int L[260];
int main()
{
int n, m, l;
cin >> n >> m >> l;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
cin >> a[i][j];
L[a[i][j]]++;
}
cout << L[0];
for (int i = 1; i < l; i++)
cout << ' ' << L[i];
}
第二题
题干太长照样附上网址叭
http://118.190.20.162/view.page?gpid=T127
第一份暴力代码,假作聪明了加了边界,结果发现超时没卵用,瞄了瞄别人写的题解,果然是前缀和,又忘记第二题是考前缀和了…
附上一篇讲前缀和挺好的文章
附上代码
#include<iostream>
using namespace std;
int a[700][700];
int b[700][700];
int main()
{
int n, L, r, t;
cin >> n >> L >> r >> t;
int c = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
{
cin >> a[i][j];
b[i][j] = b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1] + a[i][j];
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
{
int x1, x2, y1, y2;
x1 = i - r;
y1 = j - r;
x2 = i + r;
y2 = j + r;
if (x1 < 1)
x1 = 1;
if (y1 < 1)
y1 = 1;
if (x2 > n)
x2 = n;
if (y2 > n)
y2 = n;
int s = (x2 - x1+1) * (y2 - y1+1);
float h = 1.0 * (b[x2][y2] - b[x1 - 1][y2] - b[x2][y1 - 1] + b[x1 - 1][y1 - 1]) / s;
if (h <= t)
c++;
}
cout << c;
}
第三题,同样也是题目太长,附上链接
http://118.190.20.162/view.page?gpid=T126
反正就,很奇怪,第一次做这种大模拟题…emm,就是感觉是看图说话,题目中给的两个样例都过了,但最后其实就10分,很头疼,可恶的CCF居然不像CF一样告诉错误原因,下面附上代码
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string.h>
using namespace std;
int sip[2000]; //store ip
int ipto[2000]; //ip timeout
string sipname[2000]; //store ip name
int main()
{
int N, tdef, tmax, tmin;
string h;
int n;
cin >> N >> tdef >> tmax >> tmin >> h >> n;
int nowtime = 0;
for (int i = 1; i <= n; i++)
{
int t;
cin >> t;
nowtime = t;
string sn,dn,type; //source name;destination name
int ip, to; //ip,time outdate
cin >> sn>>dn>>type>>ip>>to;
if (type == "DIS")
{
if (dn != "*")
continue;
int i;
for (i = 1; i <= N; i++)
{
if (sip[i] == 1 && ipto[i] == 0)
{
sip[i] = 0;
sipname[i] = "";
}
if (sip[i] == 0)
{
sip[i] = 1;
sipname[i] = sn;
break;
}
}
if (i == N + 1)
{
for (i = 1; i <= N; i++)
{
if (sip[i] == 1)
{
if (ipto[i] < nowtime)
{
sipname[i] = sn;
ipto[i] = 0;
break;
}
}
}
}
if (i != N + 1)
{
if (to - t < tmin)
to = t+ tdef;
//ipto[i] = to;
cout << h + " " + sn + " OFR ";
cout << i;
cout << ' ';
cout << to;
cout << endl;
continue;
}
}
else if (type == "REQ")
{
if (dn != h)
continue;
if (to - t < tmin)
to = t + tdef;
if (sip[ip]&&sipname[ip]==sn)
{
ipto[ip] = to;
cout << h + " " + sn + " ACK ";
cout << ip;
cout << ' ';
cout << to;
cout << endl;
continue;
}
if (sip[ip] && sipname[ip] != sn)
{
ipto[ip] = to;
cout << h + " " + sn + " NAK ";
cout << ip;
cout << ' ';
cout << 0;
cout << endl;
continue;
}
}
else
continue;
}
}
第四题,附上题目链接:
http://118.190.20.162/view.page?gpid=T125
再附上自己参考的代码网址
https://blog.csdn.net/tigerisland45/article/details/119742968?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163776539616780271955985%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=163776539616780271955985&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~rank_v31_ecpm-3-119742968.first_rank_v2_pc_rank_v29&utm_term=ccf%E6%A0%A1%E9%97%A8%E5%A4%96%E7%9A%84%E6%A0%91&spm=1018.2226.3001.4187
有个小坑吧,using namespace std得放在vector前面定义,否则用vector得加个std::,这题有点有意思的是对因数的处理吧。
也是个dp问题,嵌套的第二个for以倒序执行的目的是防止中途有障碍物,想到用dp做,想用它的状态数来做,但是想不出来…结果还是这,其实这种方法想是想过,用前n种乘以n+1种的状态数…但是这题的思维叭,有点难以自己想出来就是。思维跨度…有点大只能说,特别是他对于障碍物的处理
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string.h>
using namespace std;
const int m = 1e5 + 10;
long long a[2000]; //obstacle position
bool c[m]; //choose or not
long long s[2000]; //score
long long mod = 1e9 + 7;
vector<int> v[m];
int main()
{
//pre process
for (int i = 1; i < m; i++)
for (int j = i * 2; j <m; j += i)
v[j].push_back(i);
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
s[1] = 1;
for (int i = 2; i <= n; i++)
{
memset(c, false, sizeof(c));
for (int j = i - 1; j > 0; j--)
{
int cnt = 0;
int d = a[i] - a[j];
for (int k : v[d])
{
if (c[k] == 0)
{
c[k] = 1;
cnt++;
}
}
c[d] = 1;
s[i] = (s[i] + s[j] * cnt % mod) % mod;
}
}
cout << s[n];
}