别问,问就是我真的很菜
2021ccpc女生赛模拟1,题目来源江西2019ccpc省赛(女?)
在一个已知字符串中随机抓取字母(有放回),组成avin的概率
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 #include <iostream> #include <algorithm> using namespace std;typedef long long ll;ll gcd (ll a,ll b) { return b>0 ?gcd (b,a%b):a; }int main () { int t; while (cin>>t) { int a, v, i, n; a = v = i = n = 0 ; for (int j = 0 ; j < t; j++) { char c; cin >> c; if (c == 'a' ) a++; if (c == 'v' ) v++; if (c == 'i' ) i++; if (c == 'n' ) n++; } if (!(a && v && i && n)) cout << "0/1" << endl; else { ll zi = a * v * i * n; ll mu = t * t * t * t; ll g = gcd (zi, mu); cout << zi / g << '/' << mu / g << endl; } } }
十字路口东->西 南->北两个方向不能同时有车辆通行,如果东西方向车辆通行时间不变,问南北方向最短等待时间是多久
开一个bool vis数组,把东西方向的输入置为true,然后南北的往这里面插空就行:
such as
input:
3 2
1 3 6
1 2
1 x 3 x x 6
1 2 然后1放到vis第二个的位置,2放到第四个位置
坑点在于如果有两辆车同一时间通行的时候,这个方法就并不好
因此…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #include <iostream> #include <cstring> using namespace std;const int maxn=10007 ;int north[maxn],nvis[maxn];int n,m;bool vis[maxn];void init () { memset (vis,false ,sizeof (vis)); memset (nvis,0 ,sizeof (nvis)); memset (north,0 ,sizeof (north)); }int main () { while (cin>>n>>m){ init (); int res=0 ; for (int i=0 ;i<n;i++){ int x;cin>>x; vis[x]=true ; } for (int i=0 ;i<m;i++){ cin>>north[i]; } for (int i=0 ;i<m;i++){ if (vis[north[i]+res]){ i=0 ; res++; } } cout<<res<<endl; } }
借此机会进行了一个逆元的学
但是我至今都不明白这个公式究竟是怎么推出来的??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include <iostream> using namespace std;typedef long long ll;const ll mod=1e9 +7 ;ll qpow (ll a,ll b) { ll res=1 ; while (b){ if (b&1 ) res=res*a%mod; a=a*a%mod; b>>=1 ; } return res; }int main () { ll n; while (cin>>n){ cout<<((n+1 )*n/2 )*qpow (n*n,mod-2 )%mod<<endl; } }
注意那个金额的取值范围是1e18 的 带三位小数的数
题目和整数部分无关,这一块直接扔掉
三位小数四舍五入为2位,测试数据挺迷惑人的,自己写几组
such as
0.005->0.01 +0 005
0.014->0.01 -0.004
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include <iostream> #include <string> #include <iomanip> using namespace std;const int maxn=1007 ;typedef long long ll;int main () { int n; while (cin>>n){ double res=0 ; for (int i=0 ;i<n;i++){ char c;string s; while (cin>>c&&c!='.' ) continue ; cin>>s; if (s[2 ]>='5' ) { res=res+10 -(s[2 ]-'0' ); } else if (s[2 ]<='4' ) { res=res-(s[2 ]-'0' ); } } cout<<fixed<<setprecision (3 )<<res/1000.0 <<endl; } }
后来补的,当时没想到最小公倍数这么做
愚蠢的人类啊
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 #include <iostream> using namespace std;typedef long long ll;const int maxn=1e6 +7 ; ll worker[maxn],house[maxn];ll gcd (ll a,ll b) { return b?gcd (b,a%b):a; }ll lcm (ll a,ll b) { return (a*b)/gcd (a,b); }int main () { ll n,m; while (cin>>n>>m) { ll x = 1 ; for (ll i = 1 ; i <= n; i++) { ll y;cin>>y; house[i]=y; x = lcm (x, y); } ll sum = 0 ; for (ll i = 1 ; i <= n; i++) { worker[i] = x / house[i]; sum += x / house[i]; } if (m % sum == 0 ) { cout << "Yes" << endl; for (ll i = 1 ; i<n; i++) { cout << worker[i] * (m / sum) << ' ' ; } cout<<worker[n]*(m/sum)<<endl; } else cout << "No" << endl; } }
签个到就快跑吧
1 2 3 4 5 6 7 8 #include <iostream> using namespace std;int main () { int x,y; cin>>x>>y; cout<<((x+y)/2 )*((x-y)/2 )<<endl; }