1202年1月16日のスタジオでの最初の毎週のコンテスト:3時間7つの質問。
AC 3/7の質問:A、E、G;
知識ポイント:論理、BFS、ユニオン検索、素数ふるい、二分法の答え、シミュレーション。
コンテストリンク<<クリックしてください!!
----------------------------------私は境界線です----------- -----------------------
ACタイトル:
A. CodeForces1A
ロジックの問題
ACコード:
#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;
}
振り返り:考え方は非常に単純で、上級コードは簡潔です!
上級問題解決策:
#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;
}
知識のポイント:素数ふるい;
ACコード:
#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;
}
反射:オイラーふるいを使用します。
質問G。。。。
反射:
スーパーウォーターの質問ですが、dddd、私は最初のQAQであまりにも慌てていました。
--------------------------------深刻な分割線--------------- ----------------------
補足:
B.CodeForces 1036Dの
知識ポイント:論理的な問題!!!配列処理の詳細を参照してください。
#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;
}
知識のポイント:シミュレーション。
ACコード:
#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;
}
振り返り:英語力が悪すぎる+長すぎる+緊張している、私はすべての質問を読んでいませんでした。。。模擬質問です。質問を理解できれば、それでも実行できます。
知識のポイント:バイナリ回答+貪欲;
ACコードは省略されています。
振り返り:二分法はまだ少し暗いです。実際、二分法は問題が理解されて
おらず、実行できないことに他なりません。。。
知識ポイント:BFS /複合検索;
ACコード:
#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;
}
振り返り:今週のコンテストの最大のメリットは、オイラースクリーンを学び、収集して使用することです。
まとめ:
道阻且长!
继续加油!
----Bzdhxs