The first weekly contest in the studio on January 16, 1202: Three hours and seven questions.
AC 3/7 questions: A, E, G;
knowledge points: logic, BFS, union search, prime number sieve, dichotomous answer, simulation.
Contest link << Click me! !
---------------------------------- I am the dividing line ------------ ----------------------
AC title:
A. CodeForces 1A
logic problem
AC code:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double n,m,a;
cin >> n >> m >> a;
long long ans;
long long x,y;
x = n / a;
y = m / a;
if(x == n / a && y == m / a) ans = x * y;
else if (x == n / a && y != m / a) ans = x * (y+1);
else if (x != n / a && y == m / a) ans = (x + 1) * y;
else if(x != n / a && y != m / a) ans = (x+1) * ( y+1);
cout << ans;
return 0;
}
Reflection: The thinking is very straightforward, and the senior code is concise!
Senior problem solution:
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n, m, a;
scanf("%lld%lld%lld", &n, &m, &a);
printf("%lld\n", (n / a + (n % a ? 1 : 0)) * (m / a + (m % a ? 1 : 0)));//三目写法更简洁
// long long A, B;
// A = n / a;
// if (n % a > 0)
// A++;
// B = m / a;
// if (m % a > 0)
// B++;
// printf("%lld\n", A * B);
return 0;
}
Knowledge points: prime number sieve ;
AC code:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
const long long Max = 1e7 + 1;
bool st[Max];
int prime[Max];
//bool isprime(int n)
//{
// if(n == 1) return false;
// if(n == 2 || n == 3) return true;
// if(n%6!=1 && n%6!=5) return false;
// int s = sqrt(n) ;
// for(int i = 5 ;i < s + 1 ; i+=6)
// if(n%i == 0 || n%(i+2) == 0) return false;
// return true;
//}
void isprime(long long n)
{
int ct = 0;
for(int i = 2 ; i < n ; i++)
{
if(st[i] == 0) prime[ct++] = i;
for(int j = 0; j < ct && i * prime[j] <= n;j++)
{
st[i*prime[j]] = 1;
if(i%prime[j]==0) break;
}
}
}
int main()
{
int T,k = 1;
cin >> T;
int ans = 0;
isprime(Max);
while(T--)
{
long long p;
cin >> p;
for(int i =2; i < p / 2 + 1;i++)
{
if(!st[i])
{
long long P = p - i;
if(!st[P] && P >= i)
{
ans++;
}
}
}
printf("Case %d: %d\n",k,ans);
ans = 0;
k++;
}
return 0;
}
Reflection: use Euler sieve;
Question G. . . .
Reflection:
Super water question but dddd, I was too flustered at first QAQ.
-------------------------------- Serious dividing line--------------- ----------------------
Supplement:
B.CodeForces 1036D
knowledge points: logic problems! ! ! See more about array processing.
#include<iostream>
using namespace std;
const int Max = 3e5 + 1;
int a[Max];
int b[Max];
int main()
{
ios::sync_with_stdio(false);
int n,m;
long long s1 = 0,s2 = 0;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
s1 += a[i];
}
cin >> m;
for(int j = 1; j <= m; j++)
{
cin >> b[j];
s2 += b[j];
}
if(s1 != s2) cout << "-1";
else
{
int ans;
s1 = s2 = 0,ans = 0;
int pos1 = 0,pos2 = 0;
while(pos1 <= n || pos2 <= m)
{
if(s1 == s2 && s1)
{
ans++, pos1++ ,pos2++;
s1 = a[pos1];
s2 = b[pos2];
}
else if(s1 == s2 && !s1)
{
s1 += a[++pos1];
s2 += b[++pos2];
}
else if(s1 < s2)
{
s1 += a[++pos1];
}
else if(s1 > s2)
{
s2 += b[++pos2];
}
}
cout << ans;
}
return 0;
}
Knowledge point: simulation.
AC code:
#include<iostream>
using namespace std;
const int N = 10001;
const int M = 300;
int a[M][M];
int s1[N];
int s2[N];
int s3[N];
int s4[N];
int j = 0;
int t,c,r,x;
int main()
{
int n,m,p;
cin >> n >> m >> p;
while(p--) // chuli;
{
cin >> t;
if(t == 1)
{
cin >> c;
j++;
s1[j] = t;
s2[j] = c;
}
else if(t == 2)
{
j++;
cin >> c;
s1[j] = t;
s2[j] = c;
}
else if(t == 3)
{
j++;
cin >> c >> r >> x;
s1[j] = t;
s2[j] = c;
s3[j] = r;
s4[j] = x;
}
}
for(int i = j; i >= 1 ;i--)
{
if(s1[i] == 1)
{
int g;
g = s2[i];
for(int k = m ; k >= 2; k--)
swap(a[g][k],a[g][k-1]);
}
else if(s1[i] == 2)
{
int g;
g = s2[i];
for(int k = n ; k >= 2; k--)
swap(a[k][g],a[k-1][g]);
}
else if(s1[i] == 3)
{
c = s2[i];
r = s3[i];
x = s4[i];
a[c][r] = x;
}
}
for(int i = 1; i <= n; i++)
{
for(int l = 1; l <= m; l++)
cout << a[i][l] << " ";
cout << endl;
}
return 0;
}
Reflection: Too bad English ability + too long + nervous, I didn't read all the questions. . . A mock question, if you can understand the question, you can still do it!
Knowledge points: binary answer + greedy;
AC code is omitted;
Reflection: Dichotomy is still a bit bleak. In fact, the dichotomy is nothing but the problem is not understood and
cannot be done. . .
Knowledge points: BFS/Combined search ;
AC code:
#include<bits/stdc++.h>
using namespace std;
const int Max = 1e5 + 100;
int pre[Max];
char mp[1010][1010];
void Init(int n)
{
for(int i = 1;i <= n; i++)
pre[i] = i;
}
int find_pre(int key)
{
if(key == pre[key])
return key;
return pre[key] = find_pre(pre[key]);
}
void unite(int x, int y)
{
int tx = find_pre(x);
int ty = find_pre(y);
if(tx != ty)
pre[tx] = ty;
}
int main()
{
int n,m;
scanf("%d %d",&n,&m);
Init(n + m + 2);
for(int i = 1; i<= n; i++) scanf("%s",mp[i] + 1);
// 并查集;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
if(mp[i][j] == '1')
{
unite(i,j + n);
}
}
int res = 0;
int jd[Max] = {
0};
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
if(mp[i][j] == '1')
{
int t = find_pre(i);
if(!jd[t]) res++, jd[t] = 1;
t = find_pre(j + n);
if(!jd[t]) res++, jd[t] = 1;
}
}
printf("%d",res);
return 0;
}
Reflection: The biggest gain of this week's competition is to learn and collect and use Euler screen;
Summary :
道阻且长!
继续加油!
----Bzdhxs