A - The Fool
HDU - 6555
题意: 求下列公式奇偶
题解: 整数分块,交给队友
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
#define endl '\n'
int solve(int n){
int ans,l,r;
ans=0;
for(l=1;l<=n;l=r+1){
r=(n/(n/l));
ans+=(n/l)*(r-l+1);
}
return ans;
}
int main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cout.setf(ios::fixed),cout.precision(3);
int t,n,ans;
cin>>t;
for(int i=1;i<=t;i++){
cin>>n;
ans=solve(n);
cout<<"Case "<<i<<": "<<(ans&1?"odd":"even")<<endl;
}
return 0;
}
B - The World
HDU - 6556
题意: 给当前城市的时间和当前城市的名称,求目标城市的时间
题解: 按照题目给的要求模拟,将当前城市时间转换成标准莫斯科时间,再转换成目标城市的时间。跟我们平时24小时计时不一样,这里的12 PM是我们平时的0 PM,12 AM是0 AM,这点非常坑,而且我代码写的很冗杂,Debug起来花了很长时间
#pragma GCC optimize(3)
#include <bits/stdc++.h>
//#include <windows.h>
#define ull unsigned long long
#define ll long long
#define pi 3.1415926
#define pll pair<ll,ll>
#define pii pair<int,int>
#define endl '\n'
#define eps 1e-6
using namespace std;
const int inf=0x3f3f3f;
const int maxn=1e5+10;
const int mod=1e9+7;
int wait=80;
ll u1[maxn];
ll u2[maxn];
int pw(int base,int p) {
int ans=1;
while(p) {
if(p&1) ans=ans*base;
base=base*base;
p>>=1;
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
int t;
cin>>t;
for(int cs=1;cs<=t;cs++) {
string a,b,c,d;
string h,m;
cin>>a>>b>>c>>d;
int s_h=0,s_m=0;
int n_h=0,n_m=0;
int ans_h=0,ans_m=0;
int f=0;
for(int i=0;i<a.length();i++) {
if(a[i]==':') {
f=1;
continue;
}
if(!f) {
h+=a[i];
}
else {
m+=a[i];
}
}
for(int i=0;i<h.length();i++) {
n_h+=(h[i]-'0')*pw(10,h.length()-i-1);
}
if(n_h==12) n_h=0;
for(int i=0;i<m.length();i++) {
n_m+=(m[i]-'0')*pw(10,m.length()-i-1);
}
if(b=="PM") {
n_h+=12;
}
//cout<<n_h<<" "<<n_m<<endl;
if(c=="Beijing") {
s_h=n_h-8;
}
else if(c=="Washington") {
s_h=n_h+5;
}
else if(c=="London") {
s_h=n_h;
}
else {
s_h=n_h-3;
}
if(d=="Beijing") {
ans_h=s_h+8;
}
else if(d=="Washington") {
ans_h=s_h-5;
}
else if(d=="London") {
ans_h=s_h;
}
else {
ans_h=s_h+3;
}
ans_m=n_m;
//cout<<ans_h<<" "<<ans_m<<endl;
cout<<"Case "<<cs<<": ";
if(ans_h>=24) {
cout<<"Tomorrow ";
ans_h-=24;
}
else if(ans_h<0) {
cout<<"Yesterday ";
ans_h+=24;
}
else {
cout<<"Today ";
}
if(ans_h>12) {
cout<<ans_h-12<<":";
}
else if(ans_h==0) cout<<"12"<<":";
else cout<<ans_h<<":";
if(ans_m==0) {
cout<<"00";
}
else if(ans_m<10) {
cout<<"0"<<ans_m;
}
else {
cout<<ans_m;
}
if(ans_h<12) {
cout<<" AM"<<endl;
}
else {
cout<<" PM"<<endl;
}
}
return 0;
}
C - Justice
HDU - 6557
题意: 给n个数,将其分成两组,使得两组数的(1/2)^x1…m求和都大于1/2
题解: 只有当1多于1个,2多于2个,3多于4个,4多于8个…n多于2^n个,才能组成一个大于1/2的数,凑出两组求和大于1/2的数即可
#pragma GCC optimize(3)
#include <bits/stdc++.h>
//#include <windows.h>
#define ull unsigned long long
#define ll long long
#define pi 3.1415926
#define pll pair<ll,ll>
#define pii pair<int,int>
#define endl '\n'
#define eps 1e-6
using namespace std;
const int inf=0x3f3f3f;
const int maxn=1e5+10;
const int mod=1e9+7;
struct node {
ll v;
int id;
}u[maxn];
int vis[maxn];
bool cmp(node a,node b) {
return a.v<b.v;
}
ll qpow(ll x,ll n) {
ll res=1;
while(n) {
if(n&1) {
res*=x;
}
n=n>>1;
x*=x;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
int t;
cin>>t;
for(int cs=1;cs<=t;cs++) {
int n;
cin>>n;
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++) {
cin>>u[i].v;
u[i].id=i;
}
sort(u+1,u+n+1,cmp);
int now=1;
int n1=1;
int n2=1;
int f=0;
ll q;
for(int i=1;i<=n;i++) {
while(n1+n2<=n-i+1&&now<u[i].v) {
n1*=2,n2*=2;
now++;
}
if(n1+n2>n-i+1) {
f=1;
break;
}
if(n1) {
n1--;
vis[u[i].id]=1;
}
else {
n2--;
}
if(!n1&&!n2) break;
}
if(f||n1||n2) cout<<"Case "<<cs<<": NO"<<endl;
else {
cout<<"Case "<<cs<<": YES"<<endl;
for(int i=1;i<=n;i++) {
cout<<vis[i];
}
cout<<endl;
}
}
return 0;
}
E - The Tower
HDU - 6559
题意: 有一个点,给定其速度向量,在坐标轴原点上有一个圆锥,给其底部半径和高,求这个点接触到圆锥的时间
题解: 解析几何,具体参考聚聚博客:
队友的代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
const double eps=1e-9;
#define endl '\n'
int dcmp(double a,double b){
if(fabs(a-b)<eps) return 0;
return a<b?-1:1;
}
double r,h,x,y,z,vx,vy,vz;
bool judge(double t){
if(t<0) return 0;
double xx=x+vx*t;
double yy=y+vy*t;
double zz=z+vz*t;
if(zz>=0&&zz<=h&&(xx*xx+yy*yy)<=r*r) return 1;
return 0;
}
int main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cout.setf(ios::fixed),cout.precision(9);
int t;
double d,A,B,C;
cin>>t;
for(int i=1;i<=t;i++){
cin>>r>>h;
cin>>x>>y>>z>>vx>>vy>>vz;
A=vz*vz-h*h*(vx*vx+vy*vy)/r/r;
B=-2*h*vz+2*z*vz-h*h*(2*vx*x+2*vy*y)/r/r;
C=h*h-2*h*z+z*z-h*h*(x*x+y*y)/r/r;
d=sqrt(B*B-4*A*C);
double as1=(-B+d)/2/A;
double as2=(-B-d)/2/A;
double ans=1e18;
if(judge(as1)) ans=min(ans,as1);
if(judge(as2)) ans=min(ans,as2);
cout<<"Case "<<i<<": "<<ans<<endl;
}
return 0;
}
F - The Hermit
HDU - 6560
题意: 别人的题意)
题解: 只有i与i-1是覆盖不到完美的信号,所以答案为rad-2
#pragma GCC optimize(3)
#include <bits/stdc++.h>
//#include <windows.h>
#define ull unsigned long long
#define ll long long
#define pi 3.1415926
#define pll pair<ll,ll>
#define pii pair<int,int>
#define endl '\n'
#define eps 1e-6
using namespace std;
const int inf=0x3f3f3f;
const int maxn=1e5+10;
const int mod=1e9+7;
int main() {
ios::sync_with_stdio(false);
int t;
cin>>t;
for(int cs=1;cs<=t;cs++) {
int n;
cin>>n;
int ans=0;
for(int i=1;i<=n;i++) {
int q;
cin>>q;
if(i>2&&q>2) {
ans^=(q-2);
}
}
cout<<"Case "<<cs<<": "<<ans<<endl;
}
}
I - Strength
HDU - 6563
题意: 你有n只怪,对面有m只怪,然后对面的怪有防守状态跟攻击状态的数值,求对对面造成最多的生命值,击败防守状态的怪兽对面不受伤,击败攻击状态的即用自己怪兽攻击力减去对面怪兽攻击力,每个怪兽只能攻击一次,即游戏王的规则
题解: 分为两种策略,第一种用最高攻击的怪去打对面的攻击状态的怪,即计算最多的穿透伤害,第二种即全灭对面的怪,再用怪去直接攻击对面。取两种策略的最大值
#pragma GCC optimize(3)
#include <bits/stdc++.h>
//#include <windows.h>
#define ull unsigned long long
#define ll long long
#define pi 3.1415926
#define pll pair<ll,ll>
#define pii pair<int,int>
#define endl '\n'
#define eps 1e-6
using namespace std;
const int inf=0x3f3f3f;
const int maxn=1e5+10;
const int mod=1e9+7;
int deftimes=0;
int n,m;
struct mon{
ll v;
bool aod;
}bob[maxn];
bool cmp(mon a,mon b) {
if(a.aod==b.aod) {
return a.v<b.v;
}
return a.aod>b.aod;
}
ll alice[maxn];
ll s1() {
ll sum=0;
int x=0,y=deftimes;
while(x<n&&y<m) {
if(alice[x]==bob[y].v) {
x++;
y++;
continue;
}
if(alice[x]>bob[y].v) {
sum+=alice[x]-bob[y].v;
x++;
y++;
}
else {
x++;
}
}
return sum;
}
ll s2() {
ll sum=0;
int x=0,y=0;
while(x<n&&y<m) {
if(alice[x]==bob[y].v) {
x++;
y++;
continue;
}
if(alice[x]>bob[y].v) {
if(!bob[y].aod) sum+=alice[x]-bob[y].v;
x++;
y++;
}
else {
bob[y].v-=alice[x];
x++;
}
}
for(x;x<n;x++) {
sum+=alice[x];
}
return sum;
}
int main() {
ios::sync_with_stdio(false);
int t;
cin>>t;
for(int cs=1;cs<=t;cs++) {
deftimes=0;
cin>>n>>m;
for(int i=0;i<n;i++) {
cin>>alice[i];
}
sort(alice,alice+n);
for(int i=0;i<m;i++) {
cin>>bob[i].v;
}
for(int i=0;i<m;i++) {
cin>>bob[i].aod;
if(bob[i].aod==1) {
deftimes++;
}
}
sort(bob,bob+m,cmp);
ll ans=0;
ans=max(ans,s1());
if(n>=m) {
ans=max(ans,s2());
}
cout<<"Case "<<cs<<": "<<ans<<endl;
}
return 0;
}