mirror of
https://github.com/wczffl-503/OI-Codes.git
synced 2025-05-10 16:20:27 +08:00
Add FZOI Codes
This commit is contained in:
parent
8f564ca60e
commit
b80791cfad
36
FZOI/ISBN号码.cpp
Normal file
36
FZOI/ISBN号码.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
char s[13];
|
||||
int main()
|
||||
{
|
||||
int sum;
|
||||
for (int i = 0; i < 13; i++)
|
||||
{
|
||||
cin >> s[i];
|
||||
}
|
||||
|
||||
sum = (s[0] - '0') * 1 + (s[2] - '0') * 2 + (s[3] - '0') * 3 + (s[4] - '0') * 4 + (s[6] - '0') * 5 + (s[7] - '0') * 6 + (s[8] - '0') * 7 + (s[9] - '0') * 8 + (s[10] - '0') * 9;//求和
|
||||
|
||||
if (sum % 11 == s[12] - '0' || (sum % 11 == 10 && s[12] == 'X'))
|
||||
{
|
||||
cout << "Right";
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
cout << s[i];
|
||||
}
|
||||
if (sum % 11 == 10)
|
||||
{
|
||||
cout << 'X';
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << sum % 11;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
18
FZOI/NOIP-CSP.cpp
Normal file
18
FZOI/NOIP-CSP.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main(){
|
||||
string s;
|
||||
cin >> s;
|
||||
int len = s.length();
|
||||
for(int i = 0; i < len; i ++ ){
|
||||
if((s[i] == 'n' || s[i] == 'N') && (s[i+1] == 'o' || s[i + 1] == 'O') && (s[i + 2] == 'i' || s[i + 2] == 'I') && (s[i + 3] == 'P' || s[i + 3] == 'p'))
|
||||
{
|
||||
cout << "CSP";
|
||||
i += 3;
|
||||
|
||||
}
|
||||
else
|
||||
cout << s[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
7
FZOI/README.md
Normal file
7
FZOI/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# 西南大学附中题目
|
||||
|
||||
仅供参考!!!
|
||||
|
||||
|
||||
|
||||
For reference only!!
|
23
FZOI/Where is Snuke? .cpp
Normal file
23
FZOI/Where is Snuke? .cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
char letter[10005] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, m;
|
||||
cin >> n >> m ;
|
||||
for(int i = 1; i <= n; ++ i)
|
||||
{
|
||||
for(int j = 1; j <= m; ++ j)
|
||||
{
|
||||
string a;
|
||||
cin >> a ;
|
||||
if(a == "snuke")
|
||||
{
|
||||
cout << letter[j - 1] << i ;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
10
FZOI/[CSP-J 2021] 分糖果.cpp
Normal file
10
FZOI/[CSP-J 2021] 分糖果.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
int n, L, R;
|
||||
cin >> n >> L >> R;
|
||||
if(R / n > L / n) cout << n - 1 << endl;
|
||||
else cout << R % n << endl;
|
||||
return 0;
|
||||
}
|
46
FZOI/[NOIP2015 普及组] 扫雷游戏.cpp
Normal file
46
FZOI/[NOIP2015 普及组] 扫雷游戏.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include<stdio.h>
|
||||
char a[101][101];
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
int n, m;
|
||||
scanf("%d%d", &n,&m);
|
||||
getchar();
|
||||
for(int i = 1; i <= n; i ++ )
|
||||
{
|
||||
for(int j = 1; j <= m; j ++ )
|
||||
{
|
||||
scanf("%c", &a[i][j]);
|
||||
}
|
||||
getchar();
|
||||
|
||||
}
|
||||
for (int i = 1; i <= n; i ++ )
|
||||
{
|
||||
for (int j = 1; j <= m; j ++ )
|
||||
{
|
||||
|
||||
if (a[i][j] == '*')
|
||||
{
|
||||
printf("*");
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = 0;
|
||||
if (a[i][j - 1] == '*') count ++ ;
|
||||
if (a[i][j + 1] == '*') count ++ ;
|
||||
if (a[i + 1][j - 1] == '*') count ++ ;
|
||||
if (a[i - 1][j + 1] == '*') count ++ ;
|
||||
if (a[i + 1][j] == '*') count ++ ;
|
||||
if (a[i - 1][j] == '*') count ++ ;
|
||||
if (a[i + 1][j + 1] == '*') count ++ ;
|
||||
if (a[i - 1][j - 1] == '*') count ++ ;
|
||||
printf("%c", count+'0');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
45
FZOI/[USACO08OPEN] Word Power S 0 天 08-20-24.cpp
Normal file
45
FZOI/[USACO08OPEN] Word Power S 0 天 08-20-24.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int n, m, tot[1001];
|
||||
string nx[1001], en[101];
|
||||
|
||||
int f(string nn,string ee)
|
||||
{
|
||||
int now = -1;
|
||||
string::size_type po = 0;
|
||||
for(int i = 0; i < ee.size(); i++)
|
||||
{
|
||||
po = nn.find(ee[i], now+1);
|
||||
if(po == nn.npos)return 0;
|
||||
now = po;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i ++ )
|
||||
{
|
||||
cin >> nx[i];
|
||||
for(int j = 0; j < nx[i].size(); j ++ )
|
||||
{
|
||||
if(nx[i][j] > 96) nx[i][j] -= 32;
|
||||
}
|
||||
}
|
||||
for(int i = 1; i <= m; i ++ )
|
||||
{
|
||||
cin >> en[i];
|
||||
for(int j = 0; j < en[i].size(); j ++ )
|
||||
{
|
||||
if(en[i][j] > 96) en[i][j] -= 32;
|
||||
}
|
||||
|
||||
for(int j = 1; j <= n; j ++ )
|
||||
{
|
||||
if(f(nx[j], en[i])) tot[j] ++ ;
|
||||
}
|
||||
}
|
||||
for(int i = 1; i <= n; i ++ ) cout << tot[i] << endl;
|
||||
}
|
37
FZOI/「201912bronze」三值排序.cpp
Normal file
37
FZOI/「201912bronze」三值排序.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#define maxn 1000+5
|
||||
int a[maxn];
|
||||
int main()
|
||||
{
|
||||
int N,num1,num2,num3,sum1,sum2,sum3;
|
||||
cin>>N;
|
||||
num1=num2=num3=sum1=sum2=sum3=0;
|
||||
for(int i=0;i<N;i++)
|
||||
{
|
||||
cin>>a[i];
|
||||
if(a[i]==1)
|
||||
num1++;
|
||||
else if(a[i]==2)
|
||||
num2++;
|
||||
else num3++;
|
||||
}
|
||||
for(int i=0;i<num1;i++)
|
||||
{
|
||||
if(a[i]!=1)
|
||||
sum1++;
|
||||
}
|
||||
for(int i=num1;i<num1+num2;i++)
|
||||
{
|
||||
if(a[i]==3)
|
||||
sum2++;
|
||||
}
|
||||
for(int i=num1+num2;i<N;i++)
|
||||
{
|
||||
|
||||
if(a[i]==2)
|
||||
sum3++;
|
||||
}
|
||||
cout<<sum1+max(sum2,sum3)<<endl;
|
||||
return 0;
|
||||
}
|
21
FZOI/「CSP-J2020」优秀的拆分.cpp
Normal file
21
FZOI/「CSP-J2020」优秀的拆分.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int n, a[30], j, k;
|
||||
int main(){
|
||||
cin >> n;
|
||||
if(n % 2 == 1) cout << -1;
|
||||
else{
|
||||
for(int i = n; i != 0; i /= 2){
|
||||
j ++ ;
|
||||
a[j] = i % 2;
|
||||
}
|
||||
k = j - 1;
|
||||
for(int i = j; i >= 1; i -- ){
|
||||
long long s = pow(2, k);
|
||||
if(a[i] != 0) cout << s << " " ;
|
||||
k -- ;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
27
FZOI/「HNOI2003」激光炸弹.cpp
Normal file
27
FZOI/「HNOI2003」激光炸弹.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int maxn = 5005;
|
||||
int s[maxn][maxn];
|
||||
int main(){
|
||||
ios::sync_with_stdio(false);
|
||||
int n,r;
|
||||
cin>>n>>r;
|
||||
int xx=r,yy=r;
|
||||
for(int i=1;i<=n;i++){
|
||||
int x,y,w;
|
||||
cin>>x>>y>>w;
|
||||
x++,y++;
|
||||
s[x][y]+=w;
|
||||
xx=max(xx,x);
|
||||
yy=max(yy,y);
|
||||
}
|
||||
for(int i=1;i<=xx;i++)
|
||||
for(int j=1;j<=yy;j++)
|
||||
s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
|
||||
int ans=0;
|
||||
for(int i=r;i<=xx;i++)
|
||||
for(int j=r;j<=yy;j++)
|
||||
ans=max(ans,s[i][j]-s[i-r][j]-s[i][j-r]+s[i-r][j-r]);
|
||||
cout<<ans;
|
||||
return 0;
|
||||
}
|
43
FZOI/「NOIP2003 普及组」乒乓球.cpp
Normal file
43
FZOI/「NOIP2003 普及组」乒乓球.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
|
||||
long long i, k = 0, w = 0, l = 0, w1 = 0, l1 = 0, a[100000], b[100000];
|
||||
char t;
|
||||
int main()
|
||||
{
|
||||
while(t != 'E')
|
||||
{
|
||||
cin >> t;
|
||||
if(t == 'W')
|
||||
{
|
||||
w ++ ;
|
||||
w1 ++ ;
|
||||
}
|
||||
else if(t == 'L')
|
||||
{
|
||||
l ++ ;
|
||||
l1 ++ ;
|
||||
}
|
||||
if((w >= 11 || l >= 11) && abs(w - l) > 1)
|
||||
{
|
||||
cout << w << ":" << l << endl;
|
||||
w = 0;
|
||||
l = 0;
|
||||
}
|
||||
if((w1 >= 21 || l1 >= 21) && abs(w1 - l1) > 1)
|
||||
{
|
||||
k ++ ;
|
||||
a[k] = w1;
|
||||
b[k] = l1;
|
||||
w1 = 0;
|
||||
l1 = 0;
|
||||
}
|
||||
}
|
||||
cout << w << ":" << l << endl << endl;
|
||||
for (i=1;i<=k;i++)
|
||||
cout << a[i] << ":" << b[i] << endl;
|
||||
cout << w1 << ":" << l1;
|
||||
return 0;
|
||||
}
|
121
FZOI/「NOIP2007」字符串的展开.cpp
Normal file
121
FZOI/「NOIP2007」字符串的展开.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int p1, p2, p3;
|
||||
cin >> p1 >> p2 >> p3 ;
|
||||
string s;
|
||||
cin >> s ;
|
||||
for(int i = 0; i < s.size(); ++ i)
|
||||
{
|
||||
if(s[i] == '-')
|
||||
{
|
||||
if(s[i - 1] >= '0' && s[i - 1] <= '9' && s[i + 1] >= '0' && s[i + 1] <= '9' && s[i + 1] > s[i - 1])
|
||||
{
|
||||
if(p1 != 3)
|
||||
{
|
||||
if(p3 == 1)
|
||||
{
|
||||
for(int j = 1; j < s[i + 1] - s[i - 1]; ++ j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << (char)(s[i - 1] + j) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(p3 == 2)
|
||||
{
|
||||
for(int j = s[i + 1] - s[i - 1] - 1; j >= 1; -- j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << (char)(s[i - 1] + j) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int j = 1; j < s[i + 1] - s[i - 1]; ++ j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << '*' ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(s[i - 1] >= 'a' && s[i - 1] <= 'z' && s[i + 1] >= 'a' && s[i + 1] <= 'z' && s[i + 1] > s[i - 1])
|
||||
{
|
||||
if(p1 == 1)
|
||||
{
|
||||
if(p3 == 1)
|
||||
{
|
||||
for(int j = 1; j < s[i + 1] - s[i - 1]; ++ j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << (char)(s[i - 1] + j) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(p3 == 2)
|
||||
{
|
||||
for(int j = s[i + 1] - s[i - 1] - 1; j >= 1; -- j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << (char)(s[i - 1] + j) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(p1 == 2)
|
||||
{
|
||||
if(p3 == 1)
|
||||
{
|
||||
for(int j = 1; j < s[i + 1] - s[i - 1]; ++ j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << (char)(s[i - 1] + j - 32) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(p3 == 2)
|
||||
{
|
||||
for(int j = s[i + 1] - s[i - 1] - 1; j >= 1; -- j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << (char)(s[i - 1] + j - 32) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int j = 1; j < s[i + 1] - s[i - 1]; ++ j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << '*' ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << s[i] ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << s[i] ;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
26
FZOI/「NOIP2011」铺地毯.cpp
Normal file
26
FZOI/「NOIP2011」铺地毯.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
int a[101000], b[101000], c[101000], d[101000];
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
|
||||
}
|
||||
int num = -1;
|
||||
int x, y;
|
||||
cin >> x >> y;
|
||||
for(int i = n; i >= 1; i--) {
|
||||
if(a[i] <= x && b[i] <= y && c[i] + a[i] >= x && d[i] + b[i] >= y)
|
||||
{
|
||||
num = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
cout << num;
|
||||
return 0;
|
||||
}
|
20
FZOI/「NOIP2012」Vigenère 密码.cpp
Normal file
20
FZOI/「NOIP2012」Vigenère 密码.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int k = -1;
|
||||
string a, b;
|
||||
int main(){
|
||||
cin >> b >> a;
|
||||
int lena = a.length(), lenb = b.length();
|
||||
for(int i = 0; i < lena; i ++ ){
|
||||
++ k;
|
||||
if(k == lenb) k -= lenb;
|
||||
char c = tolower(a[i]), d = tolower(b[k]);
|
||||
int x = (c - 'a') - (d - 'a');
|
||||
if(x < 0) x += 26;
|
||||
x ++ ;
|
||||
if(a[i] >= 'a' && a[i] <= 'z') printf("%c", x + 'a' - 1);
|
||||
else printf("%c", x + 'A' - 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
33
FZOI/「NOIP2014 普及组」珠心算测验.cpp
Normal file
33
FZOI/「NOIP2014 普及组」珠心算测验.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
bool a[20010];
|
||||
int b[20010];
|
||||
int main()
|
||||
{
|
||||
int n, x, sum = 0;
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i ++ )
|
||||
{
|
||||
cin >> x;
|
||||
a[x] = 1;
|
||||
}
|
||||
for(int i = 1; i <= 10000; i ++ )
|
||||
{
|
||||
if(a[i] == 1)
|
||||
{
|
||||
for(int j = i + 1; j <= 10000; j ++ )
|
||||
{
|
||||
if(a[j] == 1 && a[i + j] == 1)
|
||||
b[i + j] ++ ;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i = 1; i <= 20010; i ++ )
|
||||
{
|
||||
if(b[i] >= 1)
|
||||
sum ++ ;
|
||||
}
|
||||
cout << sum;
|
||||
return 0;
|
||||
}
|
18
FZOI/「NOIP2014」生活大爆炸版石头剪刀布.cpp
Normal file
18
FZOI/「NOIP2014」生活大爆炸版石头剪刀布.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int MAXN = 200 + 10;
|
||||
int n, na, nb, a[MAXN], b[MAXN], cnta, cntb;
|
||||
int vs[5][5] = {{0, 0, 1, 1, 0}, {1, 0, 0, 1, 0}, {0, 1, 0, 0, 1}, {0, 0, 1, 0, 1}, {1, 1, 0, 0, 0}};
|
||||
int main()
|
||||
{
|
||||
cin >> n >> na >> nb;
|
||||
for(int i = 0; i < na; i++) cin >> a[i];
|
||||
for(int i = 0; i < nb; i++) cin >> b[i];
|
||||
for(int i = 0; i < n; i++)
|
||||
{
|
||||
cnta += vs[a[i % na]][b[i % nb]];
|
||||
cntb += vs[b[i % nb]][a[i % na]];
|
||||
}
|
||||
cout << cnta << " " << cntb << endl;
|
||||
return 0;
|
||||
}
|
34
FZOI/「NOIP2016」玩具谜题.cpp
Normal file
34
FZOI/「NOIP2016」玩具谜题.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include<cstdio>
|
||||
using namespace std;
|
||||
const int MAXN = 100010;
|
||||
|
||||
int n, m;
|
||||
struct TOY{
|
||||
int pos;
|
||||
char name[100];
|
||||
};
|
||||
TOY toy[MAXN];
|
||||
|
||||
int main()
|
||||
{
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 1; i <= n; i ++ ) scanf("%d%s", &toy[i].pos, &toy[i].name);
|
||||
int now = 1;
|
||||
int zy, s;
|
||||
for (int i = 1; i <= m; i ++ )
|
||||
{
|
||||
scanf("%d%d", &zy, &s);
|
||||
if ((toy[now].pos == 0 && zy == 1) || (toy[now].pos == 1 && zy == 0))
|
||||
{
|
||||
now += s;
|
||||
if (now > n) now = now % n;
|
||||
}
|
||||
else
|
||||
{
|
||||
now -= s;
|
||||
if (now <= 0) now = n + now;
|
||||
}
|
||||
}
|
||||
printf("%s", toy[now].name);
|
||||
return 0;
|
||||
}
|
11
FZOI/「NOIP2018 普及组」标题统计.cpp
Normal file
11
FZOI/「NOIP2018 普及组」标题统计.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int i, l;
|
||||
string s;
|
||||
int main(){
|
||||
getline(cin, s);
|
||||
for(i = 0; i < s.size(); i ++ ){
|
||||
if(s[i] != ' ') l ++ ;
|
||||
}
|
||||
cout << l;
|
||||
}
|
42
FZOI/「POJ2456」Aggressive Cows.cpp
Normal file
42
FZOI/「POJ2456」Aggressive Cows.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
int judge(int, int);
|
||||
int arr[100000];
|
||||
int n, c;
|
||||
int main()
|
||||
{
|
||||
scanf("%d%d", &n, &c);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d", &arr[i]);
|
||||
}
|
||||
sort(arr, arr + n);
|
||||
int l = arr[0];
|
||||
int r = arr[n - 1] - arr[0];
|
||||
int D;
|
||||
while (r >= l)
|
||||
{
|
||||
D = (l + r) >> 1;
|
||||
if (judge(n, D) >= c)
|
||||
l = D + 1;
|
||||
else
|
||||
r = D - 1;
|
||||
}
|
||||
printf("%d\n", l - 1);
|
||||
return 0;
|
||||
}
|
||||
int judge(int n, int D)
|
||||
{
|
||||
int i, s = 1, p = arr[0];
|
||||
for (i = 1; i < n; i++)
|
||||
{
|
||||
if (arr[i] - p >= D)
|
||||
{
|
||||
s++;
|
||||
p = arr[i];
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
33
FZOI/「USACO1.1」Broken Necklace.cpp
Normal file
33
FZOI/「USACO1.1」Broken Necklace.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include<cstdio>
|
||||
#include<algorithm>
|
||||
#define N 355
|
||||
using namespace std;
|
||||
|
||||
char a;
|
||||
int b[N];
|
||||
int n, ans;
|
||||
|
||||
int solve(int p, int dir)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
for(int j = p + n; len < n; len ++ , j += dir)
|
||||
{
|
||||
if(b[p] && b[j%n] && b[j % n] != b[p]) break;
|
||||
if(!b[p]) p = j % n;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d ", &n);
|
||||
for(int i = 0; i < n; i ++ )
|
||||
{
|
||||
a = getchar();
|
||||
b[i] = a == 'b' ? 1 : a == 'r' ? 2 : 0;
|
||||
}
|
||||
for(int i = 0; i < n; i ++ ) ans = max(ans, solve(i, - 1) + solve(i + 1, 1));
|
||||
ans = min(ans, n);
|
||||
printf("%d\n", ans);
|
||||
return 0;
|
||||
}
|
44
FZOI/「USACO2.4」The Tamworth Two.cpp
Normal file
44
FZOI/「USACO2.4」The Tamworth Two.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 10;
|
||||
char g[N][N];
|
||||
|
||||
int dx[] = {-1, 0, 1, 0};
|
||||
int dy[] = {0, 1, 0, -1};
|
||||
|
||||
int main()
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
for (int j = 0; j < 10; j++)
|
||||
cin >> g[i][j];
|
||||
int x1, y1, x2, y2;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
for (int j = 0; j < 10; j++)
|
||||
{
|
||||
if (g[i][j] == 'C') x1 = i, y1 = j;
|
||||
if (g[i][j] == 'F') x2 = i, y2 = j;
|
||||
}
|
||||
}
|
||||
int cd = 0, fd = 0;
|
||||
int cnt = 0;
|
||||
while (true) {
|
||||
if (x1 + dx[cd] >= 10 || x1 + dx[cd] < 0 || y1 + dy[cd] >= 10 || y1 + dy[cd] < 0 || g[x1 + dx[cd]][y1 + dy[cd]] == '*') cd = (cd + 1) % 4;
|
||||
else x1 += dx[cd], y1 += dy[cd];
|
||||
if (x2 + dx[fd] >= 10 || x2 + dx[fd] < 0 || y2 + dy[fd] >= 10 || y2 + dy[fd] < 0 || g[x2 + dx[fd]][y2 + dy[fd]] == '*') fd = (fd + 1) % 4;
|
||||
else x2 += dx[fd], y2 += dy[fd];
|
||||
cnt++;
|
||||
if(x1 == x2 && y1 == y2)
|
||||
{
|
||||
cout << cnt << endl;
|
||||
break;
|
||||
}
|
||||
if (cnt > 1000000)
|
||||
{
|
||||
cout << 0 << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
29
FZOI/「USACO2007JAN」Tallest Cow.cpp
Normal file
29
FZOI/「USACO2007JAN」Tallest Cow.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include<cstdio>
|
||||
#include<cmath>
|
||||
#include<cstring>
|
||||
#include<algorithm>
|
||||
#include<map>
|
||||
using namespace std;
|
||||
|
||||
struct node {
|
||||
int first;
|
||||
int second;
|
||||
}h[10005];
|
||||
int kdl[10005][10005];
|
||||
int n, f[10005], hest, r, t, a, b, c, d;
|
||||
int main() {
|
||||
scanf("%d%d%d%d", &n, &t, &hest, &r);
|
||||
for (int i = 1; i <= n; i++) {
|
||||
f[i] = hest;
|
||||
}
|
||||
for (int i = 1; i <= r; i++) {
|
||||
scanf("%d%d", &a, &b);
|
||||
h[i].first = min(a, b);
|
||||
h[i].second = max(a, b);
|
||||
if (kdl[a][b] == 1)continue;
|
||||
kdl[a][b] = 1;
|
||||
for(int j=h[i].first+1;j<h[i].second;j++)f[j]--;
|
||||
}
|
||||
for(int i=1;i<=n;i++)printf("%d\n",f[i]);
|
||||
return 0;
|
||||
}
|
49
FZOI/「USACO2007MAR」Monthly Expense.cpp
Normal file
49
FZOI/「USACO2007MAR」Monthly Expense.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
int a[110000];
|
||||
int s[110000];
|
||||
int n, m;
|
||||
bool check(int x)
|
||||
{
|
||||
int len = 1, d = 0;
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
if (a[i] > x)
|
||||
return false;
|
||||
if (d + a[i] > x)
|
||||
{
|
||||
len++;
|
||||
d = a[i];
|
||||
if (len > m)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
d += a[i];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 1; i <= n; i++)
|
||||
scanf("%d", &a[i]);
|
||||
int l = 0, r = 1000000000;
|
||||
int ans = 0;
|
||||
while (l <= r)
|
||||
{
|
||||
int mid = (l + r) / 2;
|
||||
if (check(mid) == true)
|
||||
{
|
||||
ans = mid;
|
||||
r = mid - 1;
|
||||
}
|
||||
else
|
||||
l = mid + 1;
|
||||
}
|
||||
printf("%d\n", ans);
|
||||
return 0;
|
||||
}
|
18
FZOI/「模板」64 位整数乘法.cpp
Normal file
18
FZOI/「模板」64 位整数乘法.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
int A, B, P, ANS;
|
||||
__int128 a, b, p, ans;
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> A >> B >> P ;
|
||||
a = A;
|
||||
b = B;
|
||||
p = P;
|
||||
ans = a * b % p;
|
||||
ANS = ans;
|
||||
cout << ANS ;
|
||||
return 0;
|
||||
}
|
59
FZOI/「模板」快速排序.cpp
Normal file
59
FZOI/「模板」快速排序.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define ll long long
|
||||
int n, l, num, head[1001], tail[1001], a[100001], ans[100001];
|
||||
void selection_sort(int l, int r)
|
||||
{
|
||||
int length = r - l + 1;
|
||||
for (int i = 1; i <= length; i++)
|
||||
{
|
||||
int aim = l + i - 1;
|
||||
for (int j = l + i - 1; j <= r; j++)
|
||||
if (a[j] < a[aim])
|
||||
aim = j;
|
||||
swap(a[l + i - 1], a[aim]);
|
||||
}
|
||||
}
|
||||
signed main()
|
||||
{
|
||||
ios::sync_with_stdio(0);
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> a[i];
|
||||
|
||||
l = sqrt(n);
|
||||
num = (n - 1) / l + 1;
|
||||
for (int i = 1; i <= num - 1; i++)
|
||||
{
|
||||
head[i] = l * (i - 1) + 1;
|
||||
tail[i] = head[i] + l - 1;
|
||||
}
|
||||
head[num] = l * (num - 1) + 1;
|
||||
tail[num] = n;
|
||||
for (int i = 1; i <= num; i++)
|
||||
selection_sort(head[i], tail[i]);
|
||||
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
int aim = 0;
|
||||
for (int j = 1; j <= num; j++)
|
||||
if (head[j] <= tail[j])
|
||||
{
|
||||
aim = j;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int j = aim + 1; j <= num; j++)
|
||||
{
|
||||
if (head[j] > tail[j])
|
||||
continue;
|
||||
if (a[head[j]] < a[head[aim]])
|
||||
aim = j;
|
||||
}
|
||||
ans[i] = a[head[aim]];
|
||||
head[aim]++;
|
||||
}
|
||||
for (int i = 1; i <= n; i++)
|
||||
cout << ans[i] << ' ';
|
||||
return 0;
|
||||
}
|
37
FZOI/亲密数对.cpp
Normal file
37
FZOI/亲密数对.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int sumOfDivisors(int n) {
|
||||
int sum = 0;
|
||||
for (int i = 2; i * i <= n; i++) {
|
||||
if (n % i == 0) {
|
||||
if(i * i != n)
|
||||
{
|
||||
sum += i;
|
||||
sum += n / i;
|
||||
}
|
||||
else{
|
||||
sum += i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int N;
|
||||
cin >> N;
|
||||
|
||||
for (int i = 2; i <= N; i++) {
|
||||
for(int j = 2; j <= N; ++ j)
|
||||
{
|
||||
if(sumOfDivisors(i) == j && sumOfDivisors(j) == i && i != j)
|
||||
{
|
||||
cout << i << " " << j << endl ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
58
FZOI/任意进制转换.cpp
Normal file
58
FZOI/任意进制转换.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
long long n;
|
||||
cin >> n;
|
||||
|
||||
if(n == 0)
|
||||
{
|
||||
cout << 0 << endl << 0 << endl << 0 ;
|
||||
}
|
||||
|
||||
if(n == 1)
|
||||
{
|
||||
cout << 1 << endl << 1 << endl << 1 ;
|
||||
}
|
||||
|
||||
string binary = "";
|
||||
long long temp = n;
|
||||
while (temp > 0) {
|
||||
binary = to_string(temp % 2) + binary;
|
||||
temp /= 2;
|
||||
}
|
||||
if(n < 0)
|
||||
{
|
||||
cout << 1 << binary << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << binary << endl;
|
||||
}
|
||||
|
||||
|
||||
string octal = "";
|
||||
temp = n;
|
||||
while (temp > 0) {
|
||||
octal = to_string(temp % 8) + octal;
|
||||
temp /= 8;
|
||||
}
|
||||
cout << octal << endl;
|
||||
|
||||
string hex = "";
|
||||
temp = n;
|
||||
while (temp > 0) {
|
||||
long long remainder = temp % 16;
|
||||
if (remainder < 10) {
|
||||
hex = to_string(remainder) + hex;
|
||||
} else {
|
||||
hex = static_cast<char>('A' + (remainder - 10)) + hex;
|
||||
}
|
||||
temp /= 16;
|
||||
}
|
||||
cout << hex << endl;
|
||||
|
||||
return 0;
|
||||
}
|
20
FZOI/你知道ABC么? .cpp
Normal file
20
FZOI/你知道ABC么? .cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include<iostream>
|
||||
|
||||
using namespace std;
|
||||
typedef long long LL;
|
||||
typedef pair<int ,string> PII;
|
||||
#define x first
|
||||
#define y second
|
||||
const int N = 1e4+10;
|
||||
const int mod = 100000007;
|
||||
|
||||
int main(){
|
||||
int a[10];
|
||||
for(int i = 0; i < 7; i ++ )
|
||||
cin >> a[i];
|
||||
sort(a, a+7);
|
||||
printf("%d %d %d",a[0],a[1],a[6]-a[0]-a[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
16
FZOI/俄罗斯方块.cpp
Normal file
16
FZOI/俄罗斯方块.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include<cstdio>
|
||||
int n,a,tag;
|
||||
bool pos=true;
|
||||
signed main(void){
|
||||
scanf("%d",&n);
|
||||
scanf("%d" ,&a);
|
||||
tag =(a&1);
|
||||
for(int i=1;i<n;i++){
|
||||
scanf("%d",&a);
|
||||
if((a&1)!=tag){
|
||||
pos=false;
|
||||
}
|
||||
}
|
||||
printf("%d\n",pos?1:0);
|
||||
return 0;
|
||||
}
|
20
FZOI/取余运算 加强版.cpp
Normal file
20
FZOI/取余运算 加强版.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
int m;
|
||||
|
||||
int f(int a, int b)
|
||||
{
|
||||
if(b == 0) return 1 % m;
|
||||
else if(b % 2 == 1) return (f(a, (b - 1)) * a) % m;
|
||||
return (f(a, b / 2) * f(a, b / 2)) % m;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
int a, b;
|
||||
cin >> a >> b >> m ;
|
||||
cout << a << "^" << b << " mod " << m << "=" << f(a, b) ;
|
||||
return 0;
|
||||
}
|
33
FZOI/回文数个数.cpp
Normal file
33
FZOI/回文数个数.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool isPalindrome(int num) {
|
||||
string str = to_string(num);
|
||||
int left = 0, right = str.length() - 1;
|
||||
while (left < right) {
|
||||
if (str[left] != str[right]) {
|
||||
return false;
|
||||
}
|
||||
left++;
|
||||
right--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
int count = 0;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (isPalindrome(i)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << count << endl;
|
||||
|
||||
return 0;
|
||||
}
|
53
FZOI/地毯填补.cpp
Normal file
53
FZOI/地毯填补.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include <iostream>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
int kr, x, y;
|
||||
void fenz(int wx, int wy, int a, int b, int k);
|
||||
signed main()
|
||||
{
|
||||
cin >> kr >> x >> y;
|
||||
fenz(1, 1, x, y, kr);
|
||||
return 0;
|
||||
}
|
||||
void fenz(int wx, int wy, int a, int b, int k)
|
||||
{
|
||||
if (k == 0)
|
||||
return;
|
||||
int lsa = 2 << (k - 2);
|
||||
if (k == 1)
|
||||
lsa = 1;
|
||||
int midx = wx + lsa;
|
||||
int midy = wy + lsa;
|
||||
if (a < midx && midy <= b)
|
||||
{
|
||||
printf("%d %d %d\n", midx, midy - 1, 1);
|
||||
fenz(wx, wy, midx - 1, midy - 1, k - 1);
|
||||
fenz(wx, midy, a, b, k - 1);
|
||||
fenz(midx, wy, midx, midy - 1, k - 1);
|
||||
fenz(midx, midy, midx, midy, k - 1);
|
||||
}
|
||||
else if (midx <= a && midy > b)
|
||||
{
|
||||
printf("%d %d %d\n", midx - 1, midy, 2);
|
||||
fenz(wx, wy, midx - 1, midy - 1, k - 1);
|
||||
fenz(wx, midy, midx - 1, midy, k - 1);
|
||||
fenz(midx, wy, a, b, k - 1);
|
||||
fenz(midx, midy, midx, midy, k - 1);
|
||||
}
|
||||
else if (a < midx && b < midy)
|
||||
{
|
||||
printf("%d %d %d\n", midx, midy, 3);
|
||||
fenz(wx, wy, a, b, k - 1);
|
||||
fenz(wx, midy, midx - 1, midy, k - 1);
|
||||
fenz(midx, wy, midx, midy - 1, k - 1);
|
||||
fenz(midx, midy, midx, midy, k - 1);
|
||||
}
|
||||
else if (midx <= a && midy <= b)
|
||||
{
|
||||
printf("%d %d %d\n", midx - 1, midy - 1, 4);
|
||||
fenz(wx, wy, midx - 1, midy - 1, k - 1);
|
||||
fenz(wx, midy, midx - 1, midy, k - 1);
|
||||
fenz(midx, wy, midx, midy - 1, k - 1);
|
||||
fenz(midx, midy, a, b, k - 1);
|
||||
}
|
||||
}
|
66
FZOI/复制书稿.cpp
Normal file
66
FZOI/复制书稿.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int a[505];
|
||||
int x[505], y[505];
|
||||
|
||||
bool check(int s)
|
||||
{
|
||||
int num = 1, t = 0;
|
||||
for (int i = n; i >= 1; i--)
|
||||
{
|
||||
if (t + a[i] > s)
|
||||
t = 0, num++;
|
||||
t += a[i];
|
||||
}
|
||||
return num <= m;
|
||||
}
|
||||
|
||||
int find(int low, int high)
|
||||
{
|
||||
int mid;
|
||||
while (low + 1 < high)
|
||||
{
|
||||
mid = low + (high - low) / 2;
|
||||
if (check(mid))
|
||||
high = mid;
|
||||
else
|
||||
low = mid;
|
||||
}
|
||||
return high;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
int low = 0, high = 0;
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
high += a[i];
|
||||
low = max(low, a[i]);
|
||||
}
|
||||
int s = find(low, high);
|
||||
int t = 0, num = 1;
|
||||
for (int i = 1; i <= m; i++)
|
||||
x[i] = y[i] = 0;
|
||||
|
||||
y[1] = n;
|
||||
for (int i = n; i >= 1; i--)
|
||||
{
|
||||
if (t + a[i] > s)
|
||||
{
|
||||
t = 0;
|
||||
x[num] = i + 1;
|
||||
y[++num] = i;
|
||||
}
|
||||
t += a[i];
|
||||
}
|
||||
x[num] = 1;
|
||||
|
||||
for (int i = m; i >= 1; i--)
|
||||
cout << x[i] << " " << y[i] << endl;
|
||||
return 0;
|
||||
}
|
20
FZOI/字符串翻转 .cpp
Normal file
20
FZOI/字符串翻转 .cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
string str;
|
||||
string inpt;
|
||||
while(true)
|
||||
{
|
||||
cin >> inpt ;
|
||||
if(inpt == ".")
|
||||
{
|
||||
break;
|
||||
}
|
||||
inpt.append(1, ' ');
|
||||
str.insert(0, inpt);
|
||||
}
|
||||
cout << str ;
|
||||
return 0;
|
||||
}
|
31
FZOI/字符数组合并 .cpp
Normal file
31
FZOI/字符数组合并 .cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int arr[100005];
|
||||
|
||||
int main()
|
||||
{
|
||||
int cnt = 0;
|
||||
char ch;
|
||||
while(cnt < 2)
|
||||
{
|
||||
ch = getchar();
|
||||
|
||||
if(ch == '.')
|
||||
{
|
||||
cnt ++ ;
|
||||
}
|
||||
if(ch >= 'a' && ch <= 'z')
|
||||
{
|
||||
arr[ch] ++ ;
|
||||
}
|
||||
}
|
||||
for(int i = 97; i <= 121; ++ i)
|
||||
{
|
||||
for(int j = 1; j <= arr[i]; ++ j)
|
||||
{
|
||||
cout << (char)i ;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
42
FZOI/循环赛日程表.cpp
Normal file
42
FZOI/循环赛日程表.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
void f(vector<vector<int>> &vt, int n)
|
||||
{
|
||||
if (n == 1)
|
||||
{
|
||||
vt[0][0] = 0;
|
||||
return;
|
||||
}
|
||||
int m = n / 2;
|
||||
f(vt, m);
|
||||
for (int i = 0; i < m; ++i)
|
||||
{
|
||||
for (int j = 0; j < m; ++j)
|
||||
{
|
||||
vt[i][j + m] = vt[i][j] + m;
|
||||
vt[i + m][j] = vt[i][j + m];
|
||||
vt[i + m][j + m] = vt[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
int m;
|
||||
cin >> m;
|
||||
int n = pow(2, m);
|
||||
vector<vector<int>> vt(n, vector<int>(n));
|
||||
f(vt, n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
for (int j = 0; j < n; ++j)
|
||||
{
|
||||
cout << vt[i][j] + 1 << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
46
FZOI/数列分段.cpp
Normal file
46
FZOI/数列分段.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int maxn = 1e5 + 5;
|
||||
int n, m, l, r;
|
||||
int a[maxn];
|
||||
bool check(int x)
|
||||
{
|
||||
int sum = 0, num = 0;
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
if (sum + a[i] <= x)
|
||||
{
|
||||
sum += a[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
sum = a[i];
|
||||
num++;
|
||||
}
|
||||
}
|
||||
return num >= m;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d %d", &n, &m);
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
scanf("%d", &a[i]);
|
||||
l = max(l, a[i]);
|
||||
r += a[i];
|
||||
}
|
||||
while (l <= r)
|
||||
{
|
||||
int mid = (l + r) / 2;
|
||||
if (check(mid))
|
||||
{
|
||||
l = mid + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
printf("%d", l);
|
||||
return 0;
|
||||
}
|
23
FZOI/数列分段2.cpp
Normal file
23
FZOI/数列分段2.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int n, m, a[100010], ans, sum;
|
||||
int main()
|
||||
{
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i ++ )
|
||||
cin >> a[i];
|
||||
for(int i = 1; i <= n; i ++ )
|
||||
{
|
||||
if(sum + a[i] < m) sum += a[i];
|
||||
else
|
||||
{
|
||||
ans ++ ;
|
||||
if(sum + a[i] > m) sum = a[i];
|
||||
else sum=0;
|
||||
}
|
||||
}
|
||||
ans += (sum > 0);
|
||||
cout << ans;
|
||||
return 0;
|
||||
}
|
38
FZOI/数的组合.cpp
Normal file
38
FZOI/数的组合.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#define int long long
|
||||
|
||||
using namespace std;
|
||||
|
||||
int m, cnt = 0;
|
||||
|
||||
void f(int n, vector<int>& vt, int start) {
|
||||
if (n == 0) {
|
||||
cout << m << "=" << vt[0];
|
||||
for (int i = 1; i < vt.size(); i++) {
|
||||
cout << "+" << vt[i];
|
||||
}
|
||||
cout << endl ;
|
||||
cnt ++ ;
|
||||
} else {
|
||||
for (int i = start; i >= 1; i--) {
|
||||
if (n >= i) {
|
||||
vt.push_back(i);
|
||||
f(n - i, vt, i);
|
||||
vt.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signed main() {
|
||||
cin >> m;
|
||||
|
||||
vector<int> vt;
|
||||
f(m, vt, m - 1);
|
||||
|
||||
cout << "total=" << cnt << endl;
|
||||
|
||||
return 0;
|
||||
}
|
52
FZOI/求逆序对.cpp
Normal file
52
FZOI/求逆序对.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
const int N = 5e5 + 10;
|
||||
int tree[N];
|
||||
|
||||
void updata(int idx, int k)
|
||||
{
|
||||
while(idx <= N)
|
||||
{
|
||||
tree[idx] += k;
|
||||
idx += (idx) & (-idx);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int query(int idx)
|
||||
{
|
||||
int res = 0;
|
||||
while(idx)
|
||||
{
|
||||
res += tree[idx];
|
||||
idx -= (idx) & (-idx);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
signed main()
|
||||
{
|
||||
int n;
|
||||
cin >> n ;
|
||||
vector<int> a(n + 1);
|
||||
for(int i = 1; i <= n; ++ i)
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
vector<int> b = a;
|
||||
sort(b.begin() + 1, b.end());
|
||||
map<int, int> cnt;
|
||||
int t = 1;
|
||||
for(int i = 1; i <= n; ++ i)
|
||||
{
|
||||
if(!cnt.count(b[i])) cnt[b[i]] = t, t ++ ;
|
||||
}
|
||||
for(int i = 1; i <= n; ++ i) a[i] = cnt[a[i]];
|
||||
int ans = 0;
|
||||
for(int i = n; i >= 1; -- i)
|
||||
{
|
||||
updata(a[i], 1);
|
||||
ans += query(a[i] - 1);
|
||||
}
|
||||
cout <<ans << endl ;
|
||||
}
|
38
FZOI/田忌赛马.cpp
Normal file
38
FZOI/田忌赛马.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
const int N=2001;
|
||||
int a[N],b[N];
|
||||
|
||||
void Scanf(int &x)
|
||||
{
|
||||
x=0;
|
||||
char s=getchar();
|
||||
while(s<'0'||s>'9') s=getchar();
|
||||
while(s>='0'&&s<='9') x=x*10+s-'0',s=getchar();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Ans,n,la,lb,ra,rb,i;
|
||||
Scanf(n);
|
||||
for (i=1;i<=n;++i) Scanf(a[i]);
|
||||
for (i=1;i<=n;++i) Scanf(b[i]);
|
||||
sort(a+1,a+n+1),sort(b+1,b+n+1);
|
||||
Ans=0,la=lb=1,ra=rb=n;
|
||||
for (i=1;i<=n;++i)
|
||||
{
|
||||
if (a[ra]>b[rb]) Ans+=200,--ra,--rb;
|
||||
else if (a[ra]<b[rb]) Ans-=200,++la,--rb;
|
||||
else if (a[la]>b[lb]) Ans+=200,++la,++lb;
|
||||
else
|
||||
{
|
||||
if (a[la]<b[rb]) Ans-=200;
|
||||
++la,--rb;
|
||||
}
|
||||
}
|
||||
printf("%d\n",Ans);
|
||||
return 0;
|
||||
}
|
29
FZOI/神犇 炸弹.cpp
Normal file
29
FZOI/神犇 炸弹.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
int m;
|
||||
int arr[1000005];
|
||||
|
||||
int f(int x)
|
||||
{
|
||||
if(arr[x] == 1) return 0;
|
||||
if(x == 1) return 1;
|
||||
if(x == 2) return 2;
|
||||
if(x == 3) return 4;
|
||||
return f(x - 1) + f(x - 2) + f(x - 3);
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
int n;
|
||||
cin >> n >> m ;
|
||||
for(int i = 1; i <= m; ++ i)
|
||||
{
|
||||
int a;
|
||||
cin >> a ;
|
||||
arr[a] = 1;
|
||||
}
|
||||
cout << f(n) ;
|
||||
return 0;
|
||||
}
|
42
FZOI/算日期.cpp
Normal file
42
FZOI/算日期.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool isLeapYear(int year) {
|
||||
return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
|
||||
}
|
||||
|
||||
int daysInMonth(int year, int month) {
|
||||
if (month == 2) {
|
||||
return isLeapYear(year) ? 29 : 28;
|
||||
} else if (month == 4 || month == 6 || month == 9 || month == 11) {
|
||||
return 30;
|
||||
} else {
|
||||
return 31;
|
||||
}
|
||||
}
|
||||
|
||||
int daysFrom1970(int year, int month, int day) {
|
||||
int days = 0;
|
||||
for (int y = 1970; y < year; y++) {
|
||||
days += isLeapYear(y) ? 366 : 365;
|
||||
}
|
||||
for (int m = 1; m < month; m++) {
|
||||
days += daysInMonth(year, m);
|
||||
}
|
||||
days += day - 1;
|
||||
return days;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int year1, month1, day1, year2, month2, day2;
|
||||
cin >> year1 >> month1 >> day1;
|
||||
cin >> year2 >> month2 >> day2;
|
||||
|
||||
int days1 = daysFrom1970(year1, month1, day1);
|
||||
int days2 = daysFrom1970(year2, month2, day2);
|
||||
|
||||
cout << days2 - days1 << endl;
|
||||
|
||||
return 0;
|
||||
}
|
18
FZOI/统计单词个数.cpp
Normal file
18
FZOI/统计单词个数.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
char ch;
|
||||
int cnt = 1;
|
||||
while(ch != '.')
|
||||
{
|
||||
ch = getchar();
|
||||
if(ch == ' ')
|
||||
{
|
||||
cnt ++ ;
|
||||
}
|
||||
}
|
||||
cout << cnt ;
|
||||
return 0;
|
||||
}
|
41
FZOI/自然数拆分.cpp
Normal file
41
FZOI/自然数拆分.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void f(int n, int r, vector<int>& vt, int start, int count) {
|
||||
if (count == 0) {
|
||||
for (int i = 0; i < vt.size(); i ++ ) {
|
||||
cout << vt[i];
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
else {
|
||||
for (int i = start; i >= r; i--) {
|
||||
vt.push_back(i);
|
||||
f(n, r - 1, vt, i - 1, count - 1);
|
||||
vt.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n, r;
|
||||
cin >> n >> r;
|
||||
|
||||
vector<int> vt;
|
||||
f(n, r, vt, n, r);
|
||||
|
||||
int t = 1;
|
||||
for (int i = n; i > n - r; i--) {
|
||||
t *= i;
|
||||
}
|
||||
for (int i = 2; i <= r; i++) {
|
||||
t /= i;
|
||||
}
|
||||
|
||||
cout << "total=" << t << endl;
|
||||
|
||||
return 0;
|
||||
}
|
34
FZOI/西大附中东区食堂的空调.cpp
Normal file
34
FZOI/西大附中东区食堂的空调.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include<cstdio>
|
||||
|
||||
const int N = 1e2+5;
|
||||
|
||||
int n,m,now=0;
|
||||
int tem[3][N];
|
||||
|
||||
bool check(void){
|
||||
for(int i=0;i<n;++i){
|
||||
int t=tem[0][i],l=tem[1][i],h=tem[2][i];
|
||||
for(;now<=t;++now){
|
||||
if(m<l)++m;
|
||||
if(m>h)--m;
|
||||
if(now==t&&(m<l||m>h))return false;
|
||||
if(m>=l&&m<=h&&i!=n-1){
|
||||
if(m<tem[1][i+1]&&m<h) ++m;
|
||||
if(m>tem[2][i+1]&&m>l) --m;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
signed main(void){
|
||||
scanf("%d%d",&n,&m);
|
||||
for(int j=0;j<n;++j){
|
||||
for(int i=0;i<3;++i){
|
||||
scanf("%d",&tem[i][j]);
|
||||
}
|
||||
}
|
||||
bool flag = check();
|
||||
printf("%d\n",flag?1:0);
|
||||
return 0;
|
||||
}
|
23
FZOI/输出字母表.cpp
Normal file
23
FZOI/输出字母表.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
for(int i = 1; i <= 26; ++ i)
|
||||
{
|
||||
cout << (char)(65 + i - 1) << " ";
|
||||
if(i % 6 == 0)
|
||||
{
|
||||
cout << endl ;
|
||||
}
|
||||
}
|
||||
cout << endl ;
|
||||
for(int i = 26; i >= 1; -- i)
|
||||
{
|
||||
cout << (char)(97 + i - 1) << " ";
|
||||
if(i % 6 == 0)
|
||||
{
|
||||
cout << endl ;
|
||||
}
|
||||
}
|
||||
}
|
23
FZOI/过滤多余的空格 .cpp
Normal file
23
FZOI/过滤多余的空格 .cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
char ch;
|
||||
int space = 0;
|
||||
while(ch != '\n')
|
||||
{
|
||||
ch = getchar();
|
||||
if(ch == ' ' && space == 0)
|
||||
{
|
||||
putchar(ch);
|
||||
space = 1;
|
||||
}
|
||||
if(ch != ' ')
|
||||
{
|
||||
space = 0;
|
||||
putchar(ch);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user