Accurately Say "CocaCola"!
题目链接:
http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=2965
解题思路:
暴力打表即可。。。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int vis[805];
int cnt[805];
int main(){
memset(vis,0,sizeof(vis));
memset(cnt,0,sizeof(cnt));
for(int i = 1; i*7 <= 800; ++i)
vis[i*7] = 1;
for(int i = 1; i <= 800; ++i){
int x = i;
while(x){
if(x%10 == 7){
vis[i] = 1;
break;
}
x /= 10;
}
}
int flag = 0;
for(int i = 800; i >= 1; --i){
if(vis[i] && flag)
cnt[i] = cnt[i+1]+1;
else if(vis[i]){
cnt[i] = 1;
flag = 1;
}
else
flag = 0;
}
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
for(int i = 1; i <= 800; ++i){
if(cnt[i] >= n){
printf("%d\n",i);
break;
}
}
}
return 0;
}
Build The Electric System
题目链接:
http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=2966
解题思路:
最小生成树。。。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1000005;
int n,m;
int pa[505];
struct Edge{
int u,v,w;
}edge[N];
bool cmp(Edge a,Edge b){
return a.w < b.w;
}
int findset(int x){
if(pa[x] != x)
pa[x] = findset(pa[x]);
return pa[x];
}
int kruskal(){
int cnt = n,sum = 0;
for(int i = 0; i < m; i++){
int u = findset(edge[i].u);
int v = findset(edge[i].v);
if(u != v){
sum += edge[i].w;
pa[v] = u;
if(--cnt == 0)
break;
}
}
return sum;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i = 0; i <= n; ++i)
pa[i] = i;
int u,v,w;
for(int i = 0; i < m; ++i)
scanf("%d%d%d",&edge[i].u,&edge[i].v,&edge[i].w);
sort(edge,edge+m,cmp);
printf("%d\n",kruskal());
}
return 0;
}
Easy Task
题目链接:
http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=2969
解题思路:
简单模拟即可。。。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 1005;
int n,m;
int arr[N];
int arr2[N];
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
int tt = n+1; int sum = 0;
for(int i = 0; i < tt; ++i){
scanf("%d",&arr[i]);
if(i != n)
sum += arr[i];
}
if(sum == 0)
printf("0\n");
else{
for(int i = 0; i < tt; ++i){
int l = tt - i - 1;
arr2[i] = arr[i] * l;
}
for(int i = 0; i < n-1; ++i)
printf("%d ",arr2[i]);
printf("%d\n",arr2[n-1]);
}
}
return 0;
}
Faster, Higher, Stronger
题目链接:
http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=2970
解题思路:
水题。。。
AC代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
char str[1005];
int arr[100005];
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%s",str);
int n;
scanf("%d",&n);
for(int i = 0; i < n; ++i)
scanf("%d",&arr[i]);
sort(arr,arr+n);
if(str[0] == 'F')
printf("%d\n",arr[0]);
else
printf("%d\n",arr[n-1]);
}
return 0;
}
Give Me the Number
题目链接:
http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=2971
解题思路:
模拟即可。。。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
map<string,int> ma;
int main(){
ma.clear();
ma["zero"] = 0; ma["one"] = 1; ma["two"] = 2; ma["three"] = 3; ma["four"] = 4;
ma["five"] = 5; ma["six"] = 6; ma["seven"] = 7; ma["eight"] = 8; ma["nine"] = 9;
ma["ten"] = 10; ma["eleven"] = 11; ma["twelve"] = 12; ma["thirteen"] = 13; ma["fourteen"] = 14;
ma["fifteen"] = 15; ma["sixteen"] = 16; ma["seventeen"] = 17; ma["eighteen"] = 18; ma["nineteen"] = 19;
ma["twenty"] = 20; ma["thirty"] = 30; ma["forty"] = 40; ma["fifty"] = 50; ma["sixty"] = 60;
ma["seventy"] = 70; ma["eighty"] = 80; ma["ninety"] = 90;
int T;
scanf("%d",&T);
getchar();
while(T--){
string str,tmp = "";
getline(cin,str);
int len = str.size();
int ans = 0,tmpans = 0;
for(int i = 0; i <= len; ++i){
if(i < len && str[i] != ' ')
tmp += str[i];
else{
//cout<<tmp<<endl;
if(tmp == "million")
ans += tmpans*1000000, tmpans = 0;
else if(tmp == "thousand")
ans += tmpans*1000, tmpans = 0;
else if(tmp == "hundred")
tmpans *= 100;
else if(ma[tmp])
tmpans += ma[tmp];
tmp = "";
//cout<<tmpans<<endl;
}
}
ans += tmpans;
printf("%d\n",ans);
}
return 0;
}
Kinds of Fuwas
题目链接:
http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=2975
解题思路:
组合数学。。。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char maze[255][255];
int vis[255][255];
char fuwa[6] = "BJHYN";
int n,m;
int solve(char c){
memset(vis,0,sizeof(vis));
int cnt,res = 0;
for(int i = 0; i < n-1; ++i){
for(int j = 0; j < m-1; ++j){
if(maze[i][j] == c){
for(int k = j+1; k < m; ++k){
if(maze[i][k] == c && !vis[j][k]){
vis[j][k] = 1;
vis[k][j] = 1;
cnt = 1;
for(int p = i+1; p < n; ++p){
if(maze[p][j] == c && maze[p][k] == c)
++cnt;
}
res += cnt*(cnt-1)/2;
}
}
}
}
}
return res;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i = 0; i < n; ++i)
scanf("%s",maze[i]);
int ans = 0;
for(int i = 0; i < 5; ++i)
ans += solve(fuwa[i]);
printf("%d\n",ans);
}
return 0;
}
Light Bulbs
题目链接:
http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=2975
解题思路:
题目大意:
上面有几盏灯(灯可以看做是点),每盏灯都有一定的光照强度,求地上的能接受到最多光强的点,求这个最大的光强。
算法思想:
因为数据量不大,所以可以直接暴力枚举。
如果数据很大的话,可以使用模拟退火。
AC代码:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
struct Point{
double x,y,z;
double I;
Point(){}
Point(double _x,double _y,double _z){x = _x; y = _y; z = _z;}
}po[105];
int vis[105][105];
double get_dis(Point p,Point q){
return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y)+(p.z-q.z)*(p.z-q.z));
}
double Dis(int n,Point q){
double dis = 0;
for(int i = 0; i < n; i++){
double R = get_dis(po[i],q);
dis += po[i].I/(R*R)*(po[i].z/R);
}
return dis;
}
double solve(int n){
double ans = 0;
for(int i = -100; i <= 100; ++i){
for(int j = -100; j <= 100; ++j){
ans = max(ans,Dis(n,Point(i,j,0)));
}
}
return ans;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
for(int i = 0; i < n; i++)
scanf("%lf%lf%lf%lf",&po[i].x,&po[i].y,&po[i].z,&po[i].I);
printf("%.2lf\n",solve(n));
}
return 0;
}