A - 程序设计:掎角之势
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;
int T;
double dis(int x1,int y1,int x2,int y2){
return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}
double area(double p,double a,double b,double c){
return sqrt(p*(p-a)*(p-b)*(p-c));
}
int main(){
cin>>T;
while(T--){
double a,b,c;
int x1,x2,x3,y1,y2,y3;
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
a = dis(x1,y1,x2,y2);
b = dis(x1,y1,x3,y3);
c = dis(x2,y2,x3,y3);
if(a+b-c <eps || a+c-b<eps || b+c-a<eps){
puts("NO SOLUTION");
continue;
}
double p = (a+b+c)/2;
double s = area(p,a,b,c);
double inR = 2*s/(a+b+c);
double outR = a*b*c/(4*s);
printf("%.8lf ",inR*inR*PI);
printf("%.8lf\n",outR*outR*PI);
}
return 0;
}
B - 天上的星星
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;
int N,Q;
int arr[2020][2020];
int sum[2020][2020];
int main(){
cin>>N;
while(N--){
int x,y,w;scanf("%d %d %d",&x,&y,&w);
arr[x+1][y+1] += w;
}
for(int i = 1;i<=2001;i++){
for(int j = 1;j<=2001;j++){
sum[i][j] = arr[i][j] + sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1];
}
}
cin>>Q;
while(Q--){
int x1,y1,x2,y2;scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
x1++,x2++,y1++,y2++;
printf("%d\n",sum[x2][y2] - sum[x2][y1-1] - sum[x1-1][y2] + sum[x1-1][y1-1]);
}
return 0;
}
C - Max Sum
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
int T;
int arr[maxn],min_idx[maxn];
int main(){
cin>>T;
int kase = 0,tag = 0;
while(T--){
if(tag) puts("");tag =1;
printf("Case %d:\n",++kase);
int N;scanf("%d",&N);
for(int i = 1;i<=N;i++) {
scanf("%d",&arr[i]);
arr[i] += arr[i-1];
}
int last_min = 0;
for(int i = 1;i<=N;i++){
min_idx[i] = last_min;
if(arr[i] < arr[last_min]) last_min = i;
}
int ans = -2e9,l,r;
for(int i = 1;i<=N;i++){
if(arr[i] - arr[min_idx[i]] > ans){
ans = arr[i] - arr[min_idx[i]];
l = min_idx[i] +1,r = i;
}
}
printf("%d %d %d\n",ans,l,r);
}
return 0;
}
D - Equation
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;
int N;
int main(){
cin>>N;
if(N>1){
cout<<3*N<<" "<<2*N<<endl;
}else{
cout<<9<<" "<<8<<endl;
}
return 0;
}
E - Convert QWERTY to Dvorak
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;
string s1 = R"(-=_+qwertyuiop[]\QWERTYUIOP{}|asdfghjkl;'ASDFGHJKL:"zxcvbnm,./ZXCVBNM<>?)";
string s2 = R"([]{}',.pyfgcrl/=\"<>PYFGCRL?+|aoeuidhtns-AOEUIDHTNS_;qjkxbmwvz:QJKXBMWVZ)";
map<char,char> mp;
void initmp(){
for(int i = 0;i<s1.size();i++){
mp[s1[i]] = s2[i];
}
}
int main(){
initmp();
string s;
while(getline(cin,s)){
for(auto c:s) {
if(mp.count(c)) cout<<mp[c];
else cout<<c;
}
cout<<endl;
}
return 0;
}
F - Lunch Time
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;
int T;
struct node{
string name;
int v;
bool operator < (const node &o) const{
return v<o.v;
}
};
vector<node> ve[3];
vector<string> ans;
int main(){
cin>>T;
while(T--){
for(int i = 0;i<3;i++) ve[i].clear();
ans.clear();
int price = 0;
int a,b,c;cin>>a>>b>>c;
string name;int v;
for(int i = 1;i<=a;i++){
cin>>name>>v;
ve[0].push_back({name,v});
}
for(int i = 1;i<=b;i++){
cin>>name>>v;
ve[1].push_back({name,v});
}
for(int i = 1;i<=c;i++){
cin>>name>>v;
ve[2].push_back({name,v});
}
for(int i = 0;i<3;i++) sort(ve[i].begin(),ve[i].end());
for(int i = 0;i<3;i++){
node cur;
int len = ve[i].size();
cur = ve[i][len/2];
price += cur.v;
ans.push_back(cur.name);
}
cout<<price<<" ";
int tag = 0;
for(const auto& na:ans) {
if(tag) cout<<" ";tag = 1;
cout<<na;
}
cout<<endl;
}
return 0;
}
G - Goldbach`s Conjecture
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e7+10;
double eps = 1e-8;
int T,N;
bool vis[maxn];
int P[maxn/10],tail;
void initP(int N){
vis[0] = vis[1] = true;
for(int i = 2;i<=N;i++){
if(!vis[i]) P[tail++] = i;
for(int j = 0;P[j] <= N/i;j++){
vis[P[j] * i ] = true;
if(i%P[j] == 0) break;
}
}
}
int main(){
initP(10000000);
cin>>T;
int kase = 0;
while(T--){
scanf("%d",&N);
int cnt = 0;
for(int i = 0;i<tail && P[i]+P[i]<=N;i++){
if(!vis[N-P[i]]) cnt++;
}
printf("Case %d: %d\n",++kase,cnt);
}
return 0;
}
H - Leading and Trailing
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;
int T;
ll N,K;
ll ksm(ll a,ll b){
ll res = 1;
while(b){
if(b&1) res = (res*a)%1000;
a = (a*a)%1000;
b>>=1;
}
return res;
}
int main(){
cin>>T;
int kase = 0;
while(T--){
scanf("%lld %lld",&N,&K);
double x = K*log10(N);
double y = fmod(x,1);
int head3 = pow(10,y)*100;
printf("Case %d: %03d %03d\n",++kase,head3,(int)ksm(N,K));
}
return 0;
}
I - Clock
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;
int T;
struct Time{
string str;
int angle;
bool operator < (const Time & o) const{
if(angle != o.angle) return angle < o.angle;
return str<o.str;
}
};
vector<Time> ve;
int get_angle(string s){
int h = (s[0]-'0')*10+(s[1]-'0'),m = (s[3]-'0')*10+(s[4]-'0');
h %= 12;
int ph = h*300+5*m,pm = m*60;
return min(abs(ph-pm),3600-abs(ph-pm));
}
int main(){
cin>>T;
while(T--){
ve.clear();
for(int i = 0;i<5;i++){
string s;cin>>s;
ve.push_back({s,get_angle(s)});
}
sort(ve.begin(),ve.end());
cout<<ve[2].str<<endl;
}
return 0;
}
J - Fliptile
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
const int inf = 1e9;
double eps = 1e-8;
int N,M;
int G[20][20];
int ans[20][20],ans_cnt = inf;
int cur[20][20],cp[20][20],ok = 0,cnt = 0;
void solve(){
for(int i = 1;i<=N;i++){
for(int j = 1;j<=M;j++){
if(cp[i][j] == 1) return ;
}
}
ok = 1;
if(cnt < ans_cnt) {
ans_cnt = cnt;
memcpy(ans,cur,sizeof cur);
}else if(cnt == ans_cnt){
for(int i = 1;i<=N;i++){
for(int j = 1;j<=M;j++){
if(cur[i][j] < ans[i][j]){
memcpy(ans,cur,sizeof cur);
return ;
}
if(cur[i][j] > ans[i][j]) return ;
}
}
}
}
void fan(int x,int y){
cp[x][y] ^=1;
cp[x-1][y] ^=1;
cp[x+1][y] ^=1;
cp[x][y-1] ^=1;
cp[x][y+1] ^=1;
}
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
memset(ans,0x3f,sizeof ans);
cin>>N>>M;
for(int i = 1;i<=N;i++){
for(int j = 1;j<=M;j++){
cin>>G[i][j];
}
}
for(int i = 0;i<(1<<M);i++){
memcpy(cp,G,sizeof G);
memset(cur,0,sizeof cur);
cnt = 0;
for(int j = M-1,idx = 1;j>=0;j--,idx++){
if((i>>j) & 1 ){
cur[1][idx] = 1;cnt++;
fan(1,idx);
}
}
for(int x = 2;x<=N;x++){
for(int y = 1;y<=M;y++){
if(cp[x-1][y]){
cur[x][y] = 1;cnt++;
fan(x,y);
}
}
}
solve();
}
if(ok){
for(int i = 1;i<=N;i++){
for(int j = 1;j<=M;j++){
cout<<ans[i][j];
if(j < M) cout<<" ";
}
puts("");
}
}else{
cout<<"IMPOSSIBLE";
}
return 0;
}
K - 求数列的和
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;
int N,M;
int main(){
while(~scanf("%d %d",&N,&M)){
double cur = N,ans = 0;
while (M--){
ans += cur;
cur = sqrt(cur);
}
printf("%.2f\n",ans);
}
return 0;
}
L - 计算星期几
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;
int a,b;
ll ksm(ll a,ll b){
ll res = 1;
while(b){
if(b&1) res = res*a%7;
a = a*a%7;
b>>=1;
}
return res;
}
int main(){
cin>>a>>b;
ll t = ksm(a,b);
if(t == 0) puts("Sunday");
if(t == 1) puts("Monday");
if(t == 2) puts("Tuesday");
if(t == 3) puts("Wednesday");
if(t == 4) puts("Thursday");
if(t == 5) puts("Friday");
if(t == 6) puts("Saturday");
return 0;
}
M - 吃糖果
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;
int T;
int arr[maxn];
int main(){
cin>>T;
while(T--){
int N;scanf("%d",&N);
ll total = 0;
for(int i = 0;i<N;i++) {
scanf("%d",&arr[i]);
total += arr[i];
}
sort(arr,arr+N,greater<int>());
if(total - arr[0] >= arr[0]-1) puts("Yes");
else puts("No");
}
return 0;
}
N - 补提交卡
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;
int T,N,M;
int sum[maxn];
int main(){
cin>>T;
while(T--){
memset(sum,0,4*105);
cin>>N>>M;
int res = 0;
for(int i = 0;i<N;i++){
int idx;scanf("%d",&idx);
sum[idx] = 1;
}
for(int i = 1;i<=100;i++) sum[i] += sum[i-1];
for(int i = 1;i<=100;i++){
for(int j = i;j<=100;j++){
if(sum[j] - sum[i-1]<=M) res = max(res,j-i+1);
}
}
cout<<res<<endl;
}
return 0;
}
O - Can you solve this equation?
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;
int T;
double Y;
double f(double x){
return 8*pow(x,4) + 7*pow(x,3) + 2*pow(x,2) + 3*x + 6-Y;
}
int main(){
cin>>T;
while(T--){
cin>>Y;
double l = 0,r = 100,mid;
if(f(l) * f(r)>0) puts("No solution!");
else{
while(r-l > 1e-8){
mid = (l+r)/2;
if(f(mid)<0) l = mid;
else r = mid;
}
printf("%.4f\n",l);
}
}
return 0;
}
P - Stages
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;
int N,M;
string s;
int main(){
cin>>N>>M>>s;
sort(s.begin(),s.end());
int wei = s[0]-'a'+1,cnt = 1,last = 0;
for(int i = 1;i<s.size();i++){
if(cnt >= M) break;
if(s[i] > s[last] + 1){
wei += s[i] - 'a'+1;
cnt++;
last = i;
}
}
if(cnt<M) puts("-1");
else cout<<wei<<endl;
return 0;
}