Codeforces Round #226 div2(待更新)
A題
程式碼:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int a[105];
int main()
{
int n,m,i;
while(cin>>n>>m)
{
for(i=1;i<=n;i++)
cin>>a[i];
int ma=0;
for(i=1;i<=n-1;i++)
if(a[i]-a[i+1]>ma)
ma=a[i]-a[i+1];
ma-=m;
if(ma>0) cout<<ma<<endl;
else cout<<"0"<<endl;
}
return 0;
}
B題:
找一個串有多少個子串是包含bear的。
程式碼:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
char a[5005];
char b[5];
int main()
{
int i;
while(cin>>a)
{
int len=strlen(a);
if(len<4)
{
puts("0");
continue;
}
long long l,r;
long long res=0;
int q=1;
for(i=0;i<len-3;i++)
{
b[0]=a[i];
b[1]=a[i+1];
b[2]=a[i+2];
b[3]=a[i+3];
b[4]='\0';
l=q;
q++;
r=len-i-3;
if(strcmp(b,"bear")==0)
{
//cout<<l<<" "<<r<<endl;
res+=l*r;
q=1;
}
}
cout<<res<<endl;
}
return 0;
}
C題:
題目大意:很明顯的需要素數分解,範圍是O(10^7),光篩選素數的複雜度就是O(10^7*log(10^7)),然後後面還需要輸入哪些數字,然後查詢,查詢當然是O(1)的,很顯然需要預處理,當時想不開,實際上在篩選的時候就可以預處理,詳見程式碼:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
bool mark[10000005];
int num[10000005];
long long dp[10000005];
void sxprime()
{
int i;
for(i=0;i<=1e7;i++)
{
mark[i]=true;
dp[i]=0;
}
for(i=2;i<=1e7;i++)
{
if(mark[i])
{
dp[i]+=num[i];
for(int j=i*2;j<=1e7;j+=i)
{
mark[j]=false;
dp[i]+=num[j];
}
}
}
}
int main()
{
int i;
int n,m,x;
while(~scanf("%d",&n))
{
for(i=0;i<=1e7;i++)
num[i]=0;
while(n--)
{
scanf("%d",&x);
num[x]++;
}
sxprime();
for(i=1;i<=1e7;i++)
dp[i]=dp[i-1]+dp[i];
int l,r;
scanf("%d",&m);
while(m--)
{
scanf("%d%d",&l,&r);
l=min(l,10000001);
r=min(r,10000000);
printf("%I64d\n",dp[r]-dp[l-1]);
}
}
return 0;
}
/*
6
5 5 7 10 14 15
3
2 11
3 12
4 4
7
2 3 5 7 11 4 8
2
8 10
2 123
*/
D題是一個狀壓dp的,
然後E是一個矩陣的快速冪。
暫時沒什麼想法。
這幾天什麼也沒做。。
就把這個作為除夕的部落格了。
相關文章
- Codeforces Round #470 div2 C
- Codeforces Round #FF(255) DIV2
- Codeforces Round #226 (Div. 2)
- Educational Codeforces Round 171 div2(A~E)
- Codeforces Round 980 div2 個人題解(A~D)
- Codeforces Round 979 div2 個人題解(A~E)
- Codeforces Round 983 div2 個人題解(A~D)
- Codeforces Round #231 div2前三題
- codeforces round #201 Div2 A. Difference Row
- codeforces round #234B(DIV2) A Inna and Choose Options
- Codeforces Round 982 div2 個人題解(A~D2)
- Codeforces Round #229 (Div. 2)(C,E待續)
- codeforces round #234B(DIV2) B Inna and New Matrix of Candies
- codeforces round #234B(DIV2) C Inna and Huge Candy Matrix
- Codeforces #245(div2)
- Codeforces Round #676 (Div. 2) A - D個人題解(E題待補)
- codeforces #197(div2)
- codeforces #198(div2)
- 958-round Div2比賽
- Codeforces Round 971 (Div. 4)題解記錄(G3待補)
- Codeforces Round #174
- Codeforces Round #170
- Codeforces Round 955
- [題解](更新中)Refact.ai Match 1 (Codeforces Round 985)AI
- Codeforces #213 div2前三題
- codeforces 260 div2 A,B,C
- Codeforces Global Round 13
- Educational Codeforces Round 32
- Codeforces Beta Round #32
- Codeforces Beta Round #23
- Codeforces Round #180
- Codeforces Global Round 26
- Codeforces Global Round 27
- codeforces #215 div2前四題
- Codeforces Educational Round#98 A
- Educational Codeforces Round 1 Tutorial
- Codeforces Global Round 26 (A - D)
- Educational Codeforces Round 163