牛客2024情人节比赛
第二杯半价()
可以学学位运算实现这两个
有floor(n/2)杯享受半价,ceil(n/2)杯原价。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <bits/stdc++.h> using namespace std;int main () { int t; cin>>t; while (t--) { int n, x; cin>>n>>x; int b=(n>>1 )*(x+1 >>1 ) + (n+1 >>1 )*x; cout<<b<<endl; } }
反方向的钟,穿越时间()
这个没什么,纯模拟
注意0是12就行
下面有一个很不错的语法,来自题解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <bits/stdc++.h> using namespace std;int main () { int t; cin>>t; while (t--) { int A, B; cin>>A>>B; int a=A%12 ; bool pm = A>=12 ; if (a==0 ) a=12 ; cout<<a<<" " <<B<<" " <<"ap" [pm]<<"m" <<endl; } }
素数三元组
比较有趣,实际上也一般
考虑奇偶,因为质数除了2都是奇数
因此必须要有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 33 34 35 36 37 #include <bits/stdc++.h> #define int long long using namespace std;const int INF = 1e16 + 50 , N = 1e6 + 50 ;int a[N], primes[N], pos;bool f[N];void pre () { for (int i = 2 ; i < N; i++) { if (!f[i]) primes[pos++] = i; for (int j = 0 ; primes[j] * i < N; j++) { f[primes[j] * i] = true ; if (i % primes[j] == 0 ) break ; } } for (int i = 0 ; i < pos; i++) if (!f[primes[i] + 2 ]) a[primes[i] + 2 ] = 1 ; for (int i = 1 ; i < N; i++) a[i] += a[i - 1 ]; } void solve () { int n; std::cin >> n; std::cout << a[n] << endl; } signed main () { int Lazy_boy_ = 1 ; pre (); std::cin >> Lazy_boy_; while (Lazy_boy_--) solve (); return 0 ; }
今日是?
1 2 3 4 5 6 #include <bits/stdc++.h> using namespace std;int main () { puts ("二外有二" ); }
时间银河
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 #include <iostream> using namespace std;bool solve (int x) { if (x%4 ==0 &&x%100 !=0 ||x%400 ==0 )return true ; return false ; } int main () { int t; cin>>t; while (t--) { int a,b; cin>>a>>b; long long res=0 ; int c=a/4 ,d=b/4 ,e=a/100 ,f=b/100 ,g=a/400 ,h=b/400 ; if (a%4 ==0 )c--; if (a%100 ==0 )e--; if (a%400 ==0 )g--; res+=((d-c)*1ll *366 +(b-a+1 -(d-c))*1ll *365 ); res-=(f-e); res+=(h-g); cout<<res<<'\n' ; } return 0 ; }
白毛飞飞
这个枚举中间跳就可以
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <bits/stdc++.h> using namespace std;int main () { int n; cin>>n; for (int i=1 ;i<=n;i++){ int x; cin>>x; if (x>i) { puts ("NO" ); return 0 ; } } puts ("YES" ); }