我真的是太菜了

A. Perfect Squares
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.

A number x is said to be a perfect square if there exists an integer y such that x = y2.

Input

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array.

The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array.

It is guaranteed that at least one element of the array is not a perfect square.

Output

Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists.

Examples
input
2
4 2
output
2
input
8
1 2 4 8 16 32 64 576
output
32
Note

In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2.

让我们找最大的不perfect的number

这个直接负数都不行,排序遍历就行了

#include<bits/stdc++.h>
using namespace std;
int a[];
int main()
{
int n;
cin>>n;
for(int i=; i<n; i++)
cin>>a[i];
sort(a,a+n);
for(int i=n-; i>=; i--)
{
if(a[i]<)
{
cout<<a[i];
return ;
}
int x=sqrt(a[i]+0.5);
if(x*x!=a[i])
{
cout<<a[i];
return ;
}
}
return ;
}
B. Conan and Agasa play a Card Game
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai written on it.

They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all cards having a number strictly lesser than the number on the chosen card. Formally, if the player chooses the i-th card, he removes that card and removes the j-th card for all j such that aj < ai.

A player loses if he cannot make a move on his turn, that is, he loses if there are no cards left. Predict the outcome of the game, assuming both players play optimally.

Input

The first line contains an integer n (1 ≤ n ≤ 105) — the number of cards Conan has.

The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105), where ai is the number on the i-th card.

Output

If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes).

Examples
input
3
4 5 7
output
Conan
input
2
1 1
output
Agasa
Note

In the first example, Conan can just choose the card having number 7 on it and hence remove all the cards. After that, there are no cards left on Agasa's turn.

In the second example, no matter which card Conan chooses, there will be one one card left, which Agasa can choose. After that, there are no cards left when it becomes Conan's turn again.

这个题就是你拿走一个,在你前面比你小的你都可以拿走,虽然两个人都尽力想赢,但是明显第一个人更占光,他永远可以制裁你

然后就变成了看看其中存在不存在一个数是奇数个的,其他的也都可以转移过来这个,所以这就是先手必胜

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int a[N];
int main()
{
int n;
cin>>n;
for(int i=,x; i<n; i++)
cin>>x,a[x]++;
for(int i=;i<N;i++)
{
if(a[i]&)
{
cout<<"Conan\n";
return ;
}
}
cout<<"Agasa\n";
return ;
}
C. Travelling Salesman and Special Numbers
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 1310 = 11012, so it has 3 bits set and 13 will be reduced to 3 in one operation.

He calls a number special if the minimum number of operations to reduce it to 1 is k.

He wants to find out how many special numbers exist which are not greater than n. Please help the Travelling Salesman, as he is about to reach his destination!

Since the answer can be large, output it modulo 109 + 7.

Input

The first line contains integer n (1 ≤ n < 21000).

The second line contains integer k (0 ≤ k ≤ 1000).

Note that n is given in its binary representation without any leading zeros.

Output

Output a single integer — the number of special numbers not greater than n, modulo 109 + 7.

Examples
input
110
2
output
3
input
111111011
2
output
169
Note

In the first sample, the three special numbers are 3, 5 and 6. They get reduced to 2 in one operation (since there are two set bits in each of 3, 5 and 6) and then to 1 in one more operation (since there is only one set bit in 2).

C就是变变变,但注意到长度最长是1000,k也不是很大,可以直接预处理__builtin_popcount,这个函数可以获取当前这个数字的二进制里有多少个1,可以这样预处理去dfs,也可以组合数学去处理

#include <bits/stdc++.h>
using namespace std;
const int MD=1e9+,N=1e3+;
char s[N];
int K,n,f[N],dp[N],pre,ans;
int main()
{
scanf("%s%d",s+,&K);
n=strlen(s+);
if(K==)
{
printf("%d\n",);
return ;
}
for (int i=; i<=n; i++)
f[i]=f[__builtin_popcount(i)]+;
for(int i=; i<=n; i++)
{
for(int j=n; j; j--)
dp[j]=(dp[j]+dp[j-])%MD;
if(s[i]=='') dp[pre]++;
pre+=s[i]-'';
}
dp[pre]++;
for (int i=; i<=n; i++)
if(f[i]==K-)ans=(ans+dp[i])%MD;
if (K==) ans=(ans-+MD)%MD;
printf("%d\n",ans);
return ;
}

Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined)的更多相关文章

  1. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  3. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  4. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  5. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  7. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  8. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

  9. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

  10. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

随机推荐

  1. js读取excel数据后的时间格式转换

    使用xlsx.full.min.js 获取excel的日期数据为:37858: 拿到的整数值是日期距离1900年1月1日的天数,这时需要写一个函数转换: function formatDate(num ...

  2. html 之table标签结构学习

    一.HTML table标签结构 html 中table标签的结构情况,如下所示: <!-- table标签结构如下: <table> <thead> # thead表格 ...

  3. POJ 1067 取石子游戏 (威佐夫博奕,公式)

    题意: 有两堆石子,两个人轮流取石子.规定每次有两种取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后把石子全部取完者为胜者.给定两堆石子数量,问先手的输赢? ...

  4. python爬虫之路——Python的re模块及其方法

    介绍常用的三种方法:search(),sub(),findall() search():匹配并提取第一个符合规律的内容,然后返回一个正则表达式的对象 #提取字符串中的第一个数字 import re a ...

  5. 小技巧:unicode RLO

    unicode 控制字符 RLO 可以将位于其后的文字翻转. 于是可以被病毒利用. 如图 重命名文件,在gpj前插入unicode RLO,之后若不小心,可能会被欺骗,误以为是jpg文件. 如果修改程 ...

  6. 文本框复制代码,兼容大部分浏览器(ZeroClipboard插件、附件)

    ;;list-style-type:none;} a,img{;} body{font:12px/180% Arial, Helvetica, sans-serif ,"新宋体"; ...

  7. javaweb基础(2)_tomcat服务器配置

    一.Tomcat服务器端口的配置 Tomcat的所有配置都放在conf文件夹之中,里面的server.xml文件是配置的核心文件. 如果想修改Tomcat服务器的启动端口,则可以在server.xml ...

  8. 新手 WordPress主题制作全过程

    WordPress主题制作全过程(一):基础准备 前言: 我想大多数使用WordPress的朋友都喜欢去尝试新的主题,但是换来换去,总是找不到那么一款适合自己的,让人很郁闷.于是很多人萌生了修改现有主 ...

  9. 01_8_session

    01_8_session 1. session总结 1.1服务器的一块内存(存key-value) 1.2和客户端窗口对应(子窗口)(独一无二) 1.3客户端和服务器有对应的SessionID 1.4 ...

  10. I/O理解

    I/O是什么 我的理解I/O就是用于读写的一个流 官方解释:I/O(英语:Input/Output),即输入/输出,通常指数据在内部存储器和外部存储器或其他周边设备之间的输入和输出. node中的io ...