Codeforces Round #239 (Div. 2)

时间:2021-01-24 01:10:42

做了三个题,先贴一下代码。。。终于涨分了

A. Line to Cashier

水题

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int INF = (<<); int main()
{
int Min, n, a[], ans;
int i, j;
while(cin>>n)
{
Min = INF;
for(i = ; i < n; i++)
cin>>a[i];
for(i = ; i < n; i++)
{
ans = a[i]*;
for(j = ; j < a[i]; j++)
{
int b;
cin>>b;
ans += b*;
}
if(ans<Min)
Min = ans;
}
cout<<Min<<endl;
}
return ;
}

B. Garland

两个字符串 代表两串颜色。

下面的要构造的颜色 上面的必须有,求上面的能构造的最大的值。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = +; char a[maxn], b[maxn];
int f_a[], f_b[];
int main()
{
int i, j;
int len_a, len_b, f, ans;
while(cin>>a>>b)
{
f = ; ans = ;
memset(f_a, , sizeof(f_a));
memset(f_b, , sizeof(f_b));
len_a = strlen(a);
len_b = strlen(b);
for(i = ; i < len_a; i++)
f_a[a[i]-'a']++;
for(j = ; j < len_b; j++)
f_b[b[j]-'a']++;
for(i = ; i < ; i++)
{
if(f_b[i]>&&f_a[i]==)
f = ;
}
if(f)
cout<<ans-<<endl;
else
{
for(i = ; i < ; i++)
{
if(f_a[i]>f_b[i])
ans += f_b[i];
else
ans += f_a[i];
}
cout<<ans<<endl;
}
}
return ;
}

C. Triangle

题意:一个直角三角形,任何边都不和坐标轴平行,给定两个腰长,顶点的坐标为整数。求这个三角形的三个顶点坐标。

可能有很多符合条件的。。

思路:以给定的两个腰长,分别做圆,从左到右枚举每个x整数点, 若y点也为整数,就保存。

最后, 让两个保存的数组,任意组合。找互相垂直,而且不与坐标轴平行的输出。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = +;
const double eps = 1e-;
struct node
{
int x, y;
} a[maxn], b[maxn]; int main()
{
int a1, b1, i, j;
int aa, bb, cnt_a, cnt_b;
double m;
int n, f;
while(cin>>a1>>b1)
{
f = ;
aa = a1*a1;
bb = b1*b1;
cnt_a = ;
cnt_b = ;
for(i = -a1+; i < a1; i++)
{
if(i==)
continue;
n = sqrt(aa-i*i);
m = (double)(sqrt(aa-i*i));
if(fabs(n-m)<eps)
{
a[cnt_a].x = i;
a[cnt_a++].y = n;
}
}
for(i = -b1+; i < b1; i++)
{
if(i==)
continue;
n = sqrt(bb-i*i);
m = (double)(sqrt(bb-i*i));
if(fabs(n-m)<eps)
{
b[cnt_b].x = i;
b[cnt_b++].y = n;
}
}
//for(i = 0; i < cnt_b; i++)
//printf("%d %d\n", b[i].x, b[i].y);
for(i = ; i < cnt_a; i++)
{
for(j = ; j < cnt_b; j++)
{
if(a[i].x*b[j].x+a[i].y*b[j].y==&&a[i].x!=b[j].x&&a[i].y!=b[j].y)
{
cout<<"YES"<<endl;
printf("%d %d\n", a[i].x, a[i].y);
printf("%d %d\n", b[j].x, b[j].y); a1 = ;
b1 = ;
printf("%d %d\n", a1, b1);
f = ;
break;
}
}
if(f)
break;
}
if(f==)
cout<<"NO"<<endl;
}
return ;
}

D. Long Path

题意:有n+1个房间,现在人在1号房间,问到 n+1个房间,需要多少步。

每个房间都有两个门,当你进入这个房间的次数是 奇数次的时候走第1个门 进入房间p[i].

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int mo = +;
const int maxn = +;
int p[maxn], d[maxn]; int main()
{
int n, i, j;
int ans;
while(cin>>n)
{
memset(d, , sizeof(d));
for(i = ; i <= n; i++)
cin>>p[i];
d[] = ;
for(i = ; i <= n; i++)
{
for(j = p[i]; j < i; j++)
{
d[i] += d[j];
d[i] %= mo;
}
d[i] += ;
d[i] %= mo;
}
ans = ;
for(i = ; i <= n; i++)
ans = (ans + d[i])%mo;
cout<<ans<<endl;
}
return ;
}

Codeforces Round #239 (Div. 2)的更多相关文章

  1. Codeforces Round &num;239 &lpar;Div&period; 1&rpar;C, 407C

    题目链接:http://codeforces.com/contest/407/problem/C 题目大意:给一个长度为n的数列,m次操作,每次操作由(li, ri, ki)描述,表示在数列li到ri ...

  2. Codeforces Round &num;239 &lpar;Div&period; 2&rpar; C&period; Triangle

    time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputoutput:standard o ...

  3. Codeforces Round &num;239 &lpar;Div&period; 1&rpar; 二项式差分

    C - Curious Array 思路:对于区间[l, r]每个数加上C(i - l + k, k), 可以在l处+1, 在r+1处-1, 然后做k+1次求前缀和操作,然后就可以写啦. 然后逐层求前 ...

  4. Codeforces Round &num;239&lpar;Div&period; 2&rpar; 做后扯淡玩

    今天补了下 cf 239div2 顿时信心再度受挫 老子几乎已经木有时间了啊 坐着等死的命.哎!!! 到现在还只能做大众题,打铁都不行. 每次D题都是有思路敲错,尼玛不带这么坑爹的. 哎!不写了,写这 ...

  5. Codeforces Round &num;239 &lpar;Div&period; 1&rpar;

    B. Long Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  6. 【Codeforces Round &num;239 &lpar;Div&period; 1&rpar; B】 Long Path

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] DP,设f[i]表示第一次到i这个房间的时候传送的次数. f[1] = 0,f[2] = 2 考虑第i个位置的情况. 它肯定是从i- ...

  7. 【Codeforces Round &num;239 &lpar;Div&period; 1&rpar; A】Triangle

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 最后的直角三角形可以通过平移,将直角顶点移动到坐标原点. 然后我们只要枚举另外两个点其中一个点的坐标就好了. x坐标的范围是[1.. ...

  8. Codeforces Round &num;366 &lpar;Div&period; 2&rpar; ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round &num;354 &lpar;Div&period; 2&rpar; ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. TCP&sol;IP、Http、Socket、XMPP-从入门到深入

    TCP/IP.Http.Socket.XMPP-从入门到深入 终极iOS程序猿 2016-12-29 18:27 为了便于大家理解和记忆,我们先对这几个概念进行的介绍,然后分析他们的不同,再进行详细的 ...

  2. 快速入门系列--MVC--05行为

    Action执行包含内容比较多,主要有同步/异步Action的概念和执行过程,Authorationfilter, ActionFiltor, ResultFilter, ExceptionFilte ...

  3. java版大数相乘

    在搞ACM的时候遇到大数相乘的问题,在网上找了一下,看到了一个c++版本的 http://blog.csdn.net/jianzhibeihang/article/details/4948267 用j ...

  4. Java根据年份算出所属的生肖。

    一个小程序~ public String getYear(Integer year){ if(year<1900){ return "未知"; } Integer start ...

  5. java&period;lang&period;IllegalStateException&colon; Target host must not be null&comma; or set in parameters&period; scheme&equals;null&comma; host&equals;null&comma; path&equals;Aict&sol;listPagedAict&period;action

    原因:请求的URL地址不完整,没有找到host. 排查解决:发现HTTP请求的URL少加了项目名,导致URL地址不完整.

  6. jgs--多线程和synchronized

    多线程 多线程是我们开发人员经常提到的一个名词.为什么会有多线程的概念呢?我们的电脑有可能会有多个cpu(或者CPU有多个内核)这就产生了多个线程.对于单个CPU来说,由于CPU运算很快,我们在电脑上 ...

  7. weui开发笔记

    1.标准的weui只是一个css皮肤,当然里面有h5特性所以有一些很好的组件,比如时间选择控件.数字输入框(用于手机号等),在ios——微信中可以做到完美的展示. 2.ui框架以手机移动端为优先显示( ...

  8. 关于Unity中NGUI的Tab商城、Scrollview和打字机效果的实现

    Tab商城实例 UIToggle 和 UIToggledObjects+ Box Collider(实现商城功能必备) 1.创建两个个UI Sprite,Sprite1和Sprite2 2.给Spri ...

  9. ajax专题

    什么是ajax?他可以用来做什么? 1.首先,ajax不是一种编程语言,是一种在无需重新加载整个网页的情况下能够更新部分网页的技术. 优点:通过和后台服务器进行少量的数据交换,网页就能异步的局部跟新, ...

  10. C&num;中IEnumerable和IEnumerator区别

    IEnumerator:是一个真正的集合访问器,提供在普通集合中遍历的接口,有Current,MoveNext(),Reset(),其中Current返回的是object类型.IEnumerable: ...