Kattis
C - Jumbled Communication
答案
#include <bits/stdc++.h>
using namespace std;
const int N=100050;
vector<int>q;
int ans[10];
int xl[10];
void solve(){
int x;
cin>>x;
memset(ans,0,sizeof(ans));
q.clear();
while(x){
q.push_back(x%2);
x/=2;
}
memset(xl,0,sizeof(xl));
for(int i=0;i<q.size();i++){
xl[7-i]=q[i];
}
int xt=0,ct=7;
for(int i=7;i>=0;i--){
ans[i]=xt^xl[i];
xt=ans[i];
}
int sum=0;
for(int i=0;i<8;i++){
sum+=ans[i]*(1<<(8-i-1));
}
cout<<sum<<endl;
}
int main(){
ios::sync_with_stdio(0);
int xl;
cin>>xl;
while(xl--){
solve();
}
return 0;
}
D - Dreamer
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_bakc
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
int days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool check(int y){
if((y%4==0&&y%100!=0)||y%400==0) return 1;
else return 0;
}
void solve(){
int t;
cin>>t;
while(t--){
int dp[11];
string s1,s2,s3;
cin>>s1>>s2>>s3;
int pp=0;
//cout<<s1<<s2<<s3<<endl;
dp[++pp]=s1[0]-'0';
dp[++pp]=s1[1]-'0';
dp[++pp]=s2[0]-'0';
dp[++pp]=s2[1]-'0';
dp[++pp]=s3[0]-'0';
dp[++pp]=s3[1]-'0';
dp[++pp]=s3[2]-'0';
dp[++pp]=s3[3]-'0';
sort(dp+1,dp+9);
int res=0;
int yy=10000,mm=13,dd=13;
do{
bool flag=0;
int d=dp[1]*10+dp[2];
int m=dp[3]*10+dp[4];
int y=dp[5]*1000+dp[6]*100+dp[7]*10+dp[8];
if(y>=2000){
if(m>=1&&m<=12){
if(m!=2){
if(d>0&&d<=days[m]){
res++;
flag=1;
}
}
else{
//if(d==29) cout<<y<<" "<<check(y)<<endl;
if(check(y)){
if(d>0&&d<=29) {
res++;
flag=1;
}
}else{
if(d>0&&d<=28) {
res++;
flag=1;
}
}
}
}
}
if(flag){
//cout<<y<<" "<<m<<" "<<d<<endl;
if(y<yy) dd=d,mm=m,yy=y;
else if(y==yy){
if(m<mm) dd=d,mm=m,yy=y;
else if(m==mm){
if(d<dd) dd=d,mm=m,yy=y;
}
}
}
}while(next_permutation(dp+1,dp+9));
cout<<res;
if(res) printf(" %02d %02d %04d\n",dd,mm,yy);
else cout<<endl;
}
}
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
solve();
return 0;
}
G - Gotta Catch Em All!
答案
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#define ll long long
#define mem(a, b) memset(a, b, sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i, a, b) for (auto i = a; i <= b; ++i)
#define bep(i, a, b) for (auto i = a; i >= b; --i)
#define lowbit(x) x&(-x)
#define PII pair<int, int>
#define x first
#define y second
#define PLL pair<ll, ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 3e5 + 10;
const int M = 111;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
using namespace std;
vector<PLL> edge;
ll in[N];
bool vis[N];
void solve() {
ll n;
cin >> n;
for (ll i = 1; i < n; i++) {
ll u, v;
cin >> u >> v;
if (u > v) swap(u, v);
edge.eb(PII{u, v});
}
sort(edge.begin(), edge.end());
edge.erase(unique(edge.begin(), edge.end()), edge.end());
for (auto i : edge) in[i.x]++, in[i.y]++;
ll ans = 0;
for (ll i = 1; i <= n; i++) ans += in[i] * (in[i] - 1);
vector<vector<ll>> vp(n + 1);
for (auto i : edge) {
ll u = i.x;
ll v = i.y;
if (in[u] > in[v])
vp[u].eb(v);
else
vp[v].eb(u);
}
ll tot = 0;
for (ll i = 1; i <= n; i++) {
for (auto j : vp[i]) vis[j] = 1;
for (auto j : vp[i]) {
for (auto k : vp[j]) {
if (vis[k]) tot++;
}
}
for (auto j : vp[i]) vis[j] = 0;
}
ans -= tot * 6;
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
I - I Wanna Be The Very Best
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_bakc
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
struct node{
ll id,x,y,z;
}dp[N];
set<ll>ans;
bool cmp1(node x, node y) { return x.x > y.x;}
bool cmp2(node x, node y) { return x.y > y.y; }
bool cmp3(node x, node y) { return x.z > y.z; }
void solve(){
ll n,k;
cin>>n>>k;
for(ll i=1;i<=n;i++){
ll x,y,z;
cin>>x>>y>>z;
dp[i]={i,x,y,z};
}
sort(dp+1,dp+1+n,cmp1);
for(ll i=1;i<=k;i++) ans.insert(dp[i].id);
sort(dp+1,dp+1+n,cmp2);
for(ll i=1;i<=k;i++) ans.insert(dp[i].id);
sort(dp+1,dp+1+n,cmp3);
for(ll i=1;i<=k;i++) ans.insert(dp[i].id);
// for(auto i:ans) cout<<i<<" ";
// cout<<endl;
cout<<ans.size()<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
J - Joyless Game
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_bakc
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
void solve(){
int t;
cin>>t;
while(t--){
string s;
cin>>s;
int len=s.size();
if(s[0]!=s[len-1]){
if (len % 2 == 0) cout << "Bash"<<endl;
else cout << "Chikapu"<<endl;
}
else{
if (len % 2 != 0) cout << "Bash"<<endl;
else cout << "Chikapu"<<endl;
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}